Is it possible to include the markers in a lookahead & lookbehind search?
Example:
str = "my cat is the best pet in the world"
re.findall('(?s)(?<=cat)(.*?)(?=pet)', str)
will return "is the best" what I want is "cat is the best pet"
thanks!
Is it possible to include the markers in a lookahead & lookbehind search?
Example:
str = "my cat is the best pet in the world"
re.findall('(?s)(?<=cat)(.*?)(?=pet)', str)
will return "is the best" what I want is "cat is the best pet"
thanks!
You should just search directly for \bcat.*?pet\b
and forego with lookarounds:
str = "my cat is the best pet in the world"
m = re.findall(r'\bcat.*?pet\b', str)
print(m)
This prints:
['cat is the best pet']