Reputation: 116810
I have some text like this:
ABCPQR01 is not at all good
EFHSTU39 is somewhat nicer
and I want to capture the ABC...
and EFH...
type words. The first set of three letters can be ABC
or EFH
and the second set of three letters can be PQR
or STU
. Instead of writing two separate regexes to capture these two text elements, how can I write this as a single re.compile
statement? Any suggestions?
Upvotes: 2
Views: 81
Reputation: 551
I think this would be a pattern which would work :)
>>> re.compile("^(ABC|EFH)(PQR|STU)\d\d\b")
also you can test it at http://www.regextester.com/index2.html
Upvotes: 2
Reputation: 798546
>>> re.match('(ABC|EFH)(PQR|STU)', 'ABCPQR01 is not at all good').groups()
('ABC', 'PQR')
Upvotes: 6