Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: match n EMth/EM occurence

by mdillon (Priest)
on Mar 31, 2002 at 21:01 UTC ( [id://155654]=note: print w/replies, xml ) Need Help??


in reply to match n EMth/EM occurence

I wouldn't use a regular expression, but something like this, probably:
sub before_nth_char { my ($str, $c, $n) = @_; my $pos = -1; { $pos = index $str, $c, $pos + 1; return if $pos == -1; redo unless --$n == 0; return substr $str, 0, $pos; } } print before_nth_char("asdfasdfasdf", "a", 2), $/;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-26 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found