Reputation: 484
I'm currently looking for the correct regex to replace something like this in Python:
old_string contains:
some text
some text
<!-V
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat
V->
some text
What I've tried to replace the <!-V *** V->
part:
import re
new_string = re.sub(r"<!-V(.*?)V->", '', old_string)
But it seems not correct, maybe anyone can help me with the correct regex.
Upvotes: 3
Views: 152
Reputation: 280778
By default, .
doesn't match a line break character. If you want .
to match those too, use the DOTALL
flag:
new_string = re.sub(r"<!-V(.*?)V->", '', old_string, flags=re.DOTALL)
There's also the option of replacing .
with a character class that matches everything, by combining two complementary character classes:
[\s\S]
Upvotes: 7