Two approaches, one simple, one less so...
my $v = "lech_lecht"; #APPROACH ONE - single regex $cnt = 0; $v =~ m{ .*? (?{$cnt++}) lecht (?{$cnt+=4}) }x; print "$cnt\n"; #APPROACH TWO - feed regex output to length() $v =~ /.*?lecht/; print length $&, "\n"; __OUTPUT__ 10 10
Note, that for position, you may want to subtract one from the result, as these approaches give 1-based answers.
,welchavw
In reply to Re: index() problem
by welchavw
in thread index() problem
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |