i am struggling with regex in Python, i would like to find the position of the last token in a String.
Example:
“mydrive/projects/test/version01”
Now i would like to get the position of the symbol between “test” and “version01”
import re
txt = "mydrive/projects/test/version01"
p = re.compile("/^.*/(.*)$/")
m = re.search(p, txt)
m.group(0)
#but m.group(0) delivers None
but with this i am getting “None” i tried several things, but couldn’t get it find the pattern. By the way i got this regex from a javascript page, but i think the patterns are the same.
thank you very much!
You say: Now i would like to get the position of the symbol between “test” and “version01”.
I don’t see how the regex is going to help you much. You could try the following:
Reverse scan for the symbol, if you know what the symbol is (I am assuming you do, since it is in the regex too):
If you don’t know the separator: