in reply to Finding the index of a string with a regexp
pos SCALAR pos 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). May be modified to change that offset. Such modification will also influence the "\G" zero-width assertion in regular expressions. See perlre and perlop.
here is an example -
#!/usr/bin/perl -w my $state = "mississippi"; while ($state =~ /.i/g) { print pos($state),":",$&,$/; } __END__ 2:mi 5:si 8:si 11:pi
hope this helps!
cheers
SK
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding the index of a string with a regexp
by OnionKnight (Sexton) on Sep 09, 2005 at 23:37 UTC | |
by bart (Canon) on Sep 09, 2005 at 23:44 UTC | |
by Hue-Bond (Priest) on Sep 09, 2005 at 23:49 UTC |