I would be inclined to use os.path and string operations instead of a regex here.
Code:
import os
s="/lhome/rxh09u/gp10-srb/src/stories/world-us-canada-11836156.xml"
os.path.basename(s)[:-13]
is pretty straight forwards, and should correctly with any filename weirdness you can imagine.
If the length of the ending were variable, something like kurum's ruby solution could be done in python:
Code:
import os
s="/lhome/rxh09u/gp10-srb/src/stories/world-us-canada-11836156.xml"
'-'.join(os.path.basename(s).split('-')[:-1])
If you want to avoid importing os:
Code:
s="/lhome/rxh09u/gp10-srb/src/stories/world-us-canada-11836156.xml"
'-'.join(s.split("/")[-1].split('-')[:-1])
All in all, regexes are serious overkill for this problem.
Bookmarks