in reply to search for nth occurrence of a pattern in a line
That doesn't use either one :)use strict; use warnings; my ($str, $nth, $find, $p); $str = "dsf,sdg,hjhgj,gjkh"; $nth = 3; $find = ','; $str =~ m/(?:.*?$find){$nth}/g; $p = pos($str) - length($find); print substr($str, $p) if $p > -1;
|
|---|