开发者

How can I capture this through a regex?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜