I'm not sure I understand this regex.  It looks like you're parsing a course_id of the form `x/y/z`.  Why not use the regex to grab each of these components and then recombine them as necessary?  This would make the regex clearer; it would also make it easier to construct `Location` objects to access XModule descriptors.