more useful options | |
PerlMonks |
Regular expression * vs +by b_e_n_82 (Initiate) |
on May 20, 2008 at 08:59 UTC ( [id://687551]=perlquestion: print w/replies, xml ) | Need Help?? |
b_e_n_82 has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
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?)+)//((?:\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
Back to
Seekers of Perl Wisdom
|
|