Reputation: 699
I have a string path as:
"Z:\results\cfg3\clear1"
I need a python string method to capture whatever Number comes after cfg but before the \ . Note that string before \cfg\ and after it could change, so I cannot use string length. So, basically, with following 2 versions
"Z:\results\cfg3\clear1"
"Z:\results1\enhanced\cfg1\clear2\final"
the script should return cfg3 and cfg1 as the answers.
Any ideas using regular expression?
sedy
Upvotes: 0
Views: 28
Reputation: 5533
>>> import re
>>> re.findall(r'.*(cfg\d+).*', "Z:\results\cfg3\clear1")
['cfg3']
Upvotes: 2