Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Regular expression * vs +

by mwah (Hermit)
on May 20, 2008 at 09:54 UTC ( [id://687572]=note: print w/replies, xml ) Need Help??


in reply to Regular expression * vs +

In addition to moritz' hint, you could look into the matching process by issuing (e.g.):

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

Regards

mwa

Replies are listed 'Best First'.
Re^2: Regular expression * vs +
by ww (Archbishop) on May 20, 2008 at 11:58 UTC

    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 |

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://687572]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-24 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found