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

Re^2: printing LAST_MATCH_START/@- LAST_MATCH_END/@+ array where regex match begin/end

by perl_boy (Novice)
on Dec 29, 2021 at 13:59 UTC ( #11140003=note: print w/replies, xml ) Need Help??


in reply to Re: printing LAST_MATCH_START/@- LAST_MATCH_END/@+ array where regex match begin/end
in thread printing LAST_MATCH_START/@- LAST_MATCH_END/@+ array where regex match begin/end

thank's for the tip. and works fine and get the expected results. good thank's :)))

However I find that that PerlDoc https://perldoc.perl.org/perlvar#Variables-related-to-regular-expressions
is a bit misleading when it says that indexes/positions before and after regex match can be found in the LAST_MATCH_START/@- and LAST_MATCH_END/@+ array by printing
print $+[0], " ",$+[1], " ", $+[2], "\n" ;

again thank's for the tip :)))
  • Comment on Re^2: printing LAST_MATCH_START/@- LAST_MATCH_END/@+ array where regex match begin/end
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: printing LAST_MATCH_START/@- LAST_MATCH_END/@+ array where regex match begin/end
by tybalt89 (Prior) on Dec 29, 2021 at 22:07 UTC

    Makes sense to me...

    'abcdef' =~ /b(.)(.)./ and print "end of entire match ", $+[0], " en +d of first group ",$+[1], " end of second group ", $+[2], "\n";

    outputs:

    end of entire match 5 end of first group 3 end of second group 4

    This is exactly as expected.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2022-05-26 21:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (94 votes). Check out past polls.

    Notices?