开发者

Matching "Wibble A, B, C2, D" using PERL-regex

开发者 https://www.devze.com 2022-12-30 21:40 出处:网络
... Foo, Bar, Wibble A, B, C2, N, J, Baz, 开发者_如何学PythonQux, More, More, ... ... Bar, Qux, Wibble D, E, J, N6, O, Foo, Foo, More, More, ... and so on

... Foo, Bar, Wibble A, B, C2, N, J, Baz, 开发者_如何学PythonQux, More, More, ...

... Bar, Qux, Wibble D, E, J, N6, O, Foo, Foo, More, More, ... and so on

How do I match highlighted part of these strings using PERL-compatible regular expressions?

It starts with a word "Wibble" and continues with one or two character components separated by a comma until next word.


From what I can tell, this may work for you:

/Wibble( [A-Z]\d?,)*/


I would try:

/(Wibble(?:\s[A-Z0-9]{1,2},)+)/


/Wibble((?:\s+[A-Z0-9]{1,2},)*)/

check $1.

of course, when you say uppercase and then have numbers in your example, some exceptions have to be made.


not-at-all-serious answer: /(Wibble A, B, C2, N, J,)/

0

精彩评论

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