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

If you are already using regexes, @- is all you need. But if you are just looking for a drop-in replacement for index, well, I have used this:

sub regindex { my ($str, $rx, $pos) = @_; pos($str) = $pos || 0; $str =~ /$rx/g or return -1; return $-[0]; }

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Replies are listed 'Best First'.
Re^2: Is there a regular expression version of the index function?
by rzward (Monk) on Jun 20, 2004 at 13:13 UTC
    Thank you all for your help. I am now reading about the pos function.

    Richard

      Oops. As you demonstrated in your example, $-[0] is what I'm looking for. According to perldoc:

      "...$-[0] is the offset into the string of the beginning of the entire match..."

      Thanks again.

      Richard