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. Th开发者_Python百科e 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?
>>> re.match('(ABC|EFH)(PQR|STU)', 'ABCPQR01 is not at all good').groups()
('ABC', 'PQR')
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
加载中,请稍侯......
精彩评论