in reply to Re: Regular expression * vs +
in thread Regular expression * vs +

Close, but not sure OP wants this (from mwah's example):

687551.pl syntax OK perl 687551.pl || || || || || || || || |123-UK 123-UK 123-UK| ||

Whereas:

my $txt = '-UK 123 123-UK 123-UK 123-UK abc-oops!'; print "|$1|\n" while $txt =~ /((?:\d+-UK\s))/g;

produces

perl 687551.pl |123-UK | |123-UK | |123-UK |

Replies are listed 'Best First'.
Re^3: Regular expression * vs +
by mwah (Hermit) on May 20, 2008 at 13:22 UTC

    I think the OP struggled over the difference between

    ... my $txt='-UK 123 123-UK 123-UK 123-UK'; print "|$1| - match until pos:" . pos($txt) . "\n" while $txt=~/((?:\ +d+-UK\W?)+)/g ; ...

    and

    ... my $txt='-UK 123 123-UK 123-UK 123-UK'; print "|$1| - match until pos:" . pos($txt) . "\n" while $txt=~/((?:\ +d+-UK\W?)*)/g ; ...

    which is the difference between (expr)+ and (expr)*, the latter matching everywhere and (of course) at 'expr', the former matching only at 'expr'.

    (maybe I misinterpreted his intention)

    Regards

    mwa