With split
my $string = "12 34 56 78 90 98 76 54 32 10"; my $n = 3; print+ (split( /[^\d+]/, $string))[$n-1]; # output => 56 my $string ='abcabbcabbbbcabcabbcab'; my $n = 3; print+ (split( /[^(?:ab+)]/, $string ))[$n-1]; # output => abbbb
In reply to Re: How do I find the Nth occurrence of a pattern?
by poolpi
in thread How do I find the Nth occurrence of a pattern?
by vroom
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |