Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Identifying the position of match using regular expressions

by tinita (Parson)
on Sep 15, 2012 at 10:59 UTC ( #993865=note: print w/replies, xml ) Need Help??

in reply to Identifying the position of match using regular expressions

if you are using the /g modifier in your regex, you can use pos($string) to get the position after the match.
generally you can use the @- and @+ arrays to get all match offsets and ends.
my $s = "ABCDFEFFAA"; $s =~ m/AA/; say "$-[0] $+[0]"; __END__ 8 10
see perlvar

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993865]
[LanX]: yes, test passed :)
[sierpinski]: woo hoo! you can go home for the day now
[Eily]: does this mean you'll give up the random prefix solution LanX?
[LanX]: yep, sorry ;(
[Eily]: such a fine and clever workaround though...
[LanX]: well even my random fingers have memory ...
[Eily]: you could have tried randomly swapping your fingers
[Eily]: enigma style

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (13)
As of 2017-03-28 13:01 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (331 votes). Check out past polls.