I need to match the string "foo" from a string with this format:
string = "/foo/boo/poo"
I tied this code:
poo = "poo"
foo = re.match('.*(?=/' + re.escape(poo) + ')', string).group(0)
and it gives me /foo/boo
as the content of the variable foo (instead of just foo/boo
).
I tried this code:
poo = "poo"
foo = re.match('(?=/).*(?=/' + re.escape(poo) + ')', string).group(0)
and I'm getting the same output (/foo/boo
instead of foo/boo
).
How can I match only the foo/boo
part?
re.search
there, notre.match
. Compare #46502300 – Cruiser