Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Is there a regular expression version of the index function?

by rob_au (Abbot)
on Jun 20, 2004 at 12:16 UTC ( #368271=note: print w/ replies, xml ) Need Help??


in reply to Is there a regular expression version of the index function?

You can do this using the pos function when performing matching against a string - This 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).

The following code demonstrates this function in action:

#!/opt/bin/perl $str = 'The quick brown fox jumps over the lazy dog.'; while ( $str =~ /[aeiou]/ig ) { printf( "%d %s\n", pos( $str ), substr( $str, pos( $str ) - 1 ) ); substr( $str, 0, pos( $str ), '' ); }

 

perl -le "print unpack'N', pack'B32', '00000000000000000000001011100101'"


Comment on Re: Is there a regular expression version of the index function?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2015-07-04 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls