views:

24

answers:

4

... Foo, Bar, Wibble A, B, C2, N, J, Baz, Qux, 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.

A: 

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

sreservoir
There could anything after "Wibble", but no longer than two characters and in upper case.
sanmai
+2  A: 

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

/Wibble( [A-Z]\d?,)*/
Amber
this does not actually capture anything other than the last `( [A-Z]\d?,)*` matched, which is generally useless. (it's something like ` J,`
sreservoir
@sreservoir for the purpose of replacing, this one is pretty fine. Thanks for the tip, Amber!
sanmai
+1  A: 

/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.

sreservoir
+1  A: 

I would try:

/(Wibble(?:\s[A-Z0-9]{1,2},)+)/
Gabriel Hurley
this, too, does not actually capture what he seems to want.
sreservoir