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

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'"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://368271]
[Corion]: Ouch. I just learned something about Chrome - the "version numbers" are not really feature numbers... Chrome 62 still gets new features even though Chrome 64 is out and Chrome 65 is the dev version
[erix]: why ouch? Something to be said for that ,surely?

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2017-12-12 20:11 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (335 votes). Check out past polls.