Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: •Re: positions of all regexp matches

by flounder99 (Friar)
on Oct 14, 2003 at 18:58 UTC ( [id://299216]=note: print w/replies, xml ) Need Help??


in reply to •Re: positions of all regexp matches
in thread positions of all regexp matches

Look, ma, no loops!
use re 'eval'; my $string = "hello world ballloon"; my $regex = qr/ll/; my @matches; () = $string =~ /(?=$regex)(?{push @matches, pos})./g; print join "\n", @matches; __END__ 2 14 15

--

flounder

Replies are listed 'Best First'.
•Re: Re: •Re: positions of all regexp matches
by merlyn (Sage) on Oct 14, 2003 at 19:06 UTC
      You are right about the not finding the \n since I didn't add an s at the end of the m//. But if you don't have the . in there it will find the positions twice.
      use re 'eval'; my $string = "he\nllo world ba\nllloon"; my $regex = qr/\nll/; my @matches; () = $string =~ /(?=$regex)(?{push @matches, pos})./sg; print "with .\n", join "\n", @matches; @matches = (); () = $string =~ /(?=$regex)(?{push @matches, pos})/sg; print "\n\nwithout .\n", join "\n", @matches; __END__ with . 2 15 without . 2 2 15 15

      --

      flounder

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found