Bruno Desthuilliers wrote: > don a écrit : >> Also if there is a better way than using regex, please let me know. > > s ="/main/parallel_branch_1/release_branch_1.0/dbg_for_python/CHECKEDOUT > from /main/parallel_branch_1/release_branch_1.0/4" > parts = s.replace(' ', '/').strip('/').split('/') > branch = parts[parts.index('CHECKEDOUT') - 1]
I wouldn't call these better (or worse) than regexes, but a slight variation on the above: marker = s.index('/CHECKEDOUT') branch = s [s.rindex('/', 0, marker) + 1 : marker] This version will throw exceptions when the marker isn't found, which may or may not be preferable under the circumstances. -- http://mail.python.org/mailman/listinfo/python-list