b_e_n_82 has asked for the wisdom of the Perl Monks concerning the following question:
I have a string like "-UK 123 123-UK 123-UK 123-UK" where I want to match all '123-UK' repetitions (in the real problem the repetitions could be any number). I was wondering if someone could enlighten me why these two expressions do not give the same results when evaluating $1:
/((?:\d+-UK\W?)+)/The former works (giving $1 as "123-UK 123-UK 123-UK") but the latter does not ($1 is null). In the later expression the '*' makes the group optional, but since the group exists I would expect it to match.
Many thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regular expression * vs +
by moritz (Cardinal) on May 20, 2008 at 09:06 UTC | |
|
Re: Regular expression * vs +
by mwah (Hermit) on May 20, 2008 at 09:54 UTC | |
by ww (Archbishop) on May 20, 2008 at 11:58 UTC | |
by mwah (Hermit) on May 20, 2008 at 13:22 UTC | |
|
Re: Regular expression * vs +
by carol (Beadle) on May 20, 2008 at 15:16 UTC | |
|
Re: Regular expression * vs +
by b_e_n_82 (Initiate) on May 20, 2008 at 16:05 UTC | |
|
Re: Regular expression * vs +
by carol (Beadle) on May 20, 2008 at 14:58 UTC |