Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: index() problem

by welchavw (Pilgrim)
on Feb 06, 2004 at 02:50 UTC ( #326970=note: print w/ replies, xml ) Need Help??


in reply to index() problem

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


Comment on Re: index() problem
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-07-10 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (198 votes), past polls