I would like to find nth occurence of a digit or character using regex in perl.
For example: If the string is:
$string = 'abdg2jj4jdh5jfj6'
i need to match the digit 5 which is the 3rd digit.
How can i do it with regex.
my $string = "abdg2jj4jdh5jfj6";
my @myArray = ($string =~ /(\d)/g);
print "$myArray[2]\n";
Output:
5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With