Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Identifying the position of match using regular expressions

by CountZero (Bishop)
on Sep 15, 2012 at 08:10 UTC ( #993854=note: print w/ replies, xml ) Need Help??


in reply to Identifying the position of match using regular expressions

use the pos function.

Returns the offset of where the last m//g search left off for the variable in question ($_ is used when the variable is not specified). Note that 0 is a valid match offset. undef indicates that the search position is reset (usually due to match failure, but can also be because no match has yet been run on the scalar).
while (<DATA>) { /\d/g; say pos; } __DATA__ AB1CDEFGHIJKLM ABCDEFGHIJKLM7 ABCDEF7GHIJKLM ABC33DEFGHIJKLM ABCDEFGH123IJKLM ABCDEFGHIJKLM 12ABCDEFGHIJKLM

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics


Comment on Re: Identifying the position of match using regular expressions
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (13)
As of 2014-07-23 12:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (141 votes), past polls