http://regex101.com/r/oU6eI5/1 , test here seam works, but when i put in Python, match whole str.
str = galley/files/tew/tewt/tweqt/ re.sub(\'^.+/+([^/]+/$)\', \
It would be better if you define the pattern or regex as raw string.
>>> import re >>> s = "galley/files/tew/tewt/tweqt/" >>> m = re.sub(r'^.+/+([^/]+/$)', r'\1', s) ^ ^ >>> m 'tweqt/'