I have looked at lots of posts with similar title but I have found nothing that works with python or even this site: https://regex101.com
How can I match everything but a specific text?
My text:
1234_This is a text Word AB
Protocol Address ping
Internet 1.1.1.1 -
Internet 1.1.1.2 25
Internet 1.1.1.3 8
Internet 1.1.1.4 -
1234_This is a text Word BCD
Protocol Address ping
Internet 2.2.2.1 10
Internet 2.2.2.2 -
I want to match Word \w+
and then the rest until the next 1234.
So the result should be (return groups marked in ()
):
(1234_This is a text (Word AB))(
Protocol Address ping
Internet 1.1.1.1 -
Internet 1.1.1.2 25
Internet 1.1.1.3 8
Internet 1.1.1.4 -
)(1234_This is a text (Word BCD)(
Protocol Address ping
Internet 2.2.2.1 10
Internet 2.2.2.2 - )
The first part is easy as: matches = re.findall(r'1234_This is a text (Word \w+)', var)
But the next part I am unable to achieve.
I have tried negative lookahead:
^(?!1234)
but then it matches nothing any more...