Reputation: 691
I'm really stuck with regex in python. I have a string with items like this:
"""
(001,002) SI [SomeTag]:Element
(001,003e) LO [SomeTag2]:Element2
(001,004r) LR [SomeTag3]:Element3
(001,006) HI [SomeTag4]:Element4
"""
And I want to select "Element2". I tried to select the line with
me = re.search("\(001,003e\)(.*)", obj)
And it gives me the whole line. But I just want "Element2". How can I select everything in the line that regex matches (e.g "(001,003e)") that is after the ':'.
Thanks in advance!
Upvotes: 2
Views: 852
Reputation: 29867
Adding the comment above as an aswer:
You can use a negated character class and use \(001,003e\)[^:]*:(.*)
. The second group will return 'Element2'.
Upvotes: 2