I was trying to match a character/letter/symbol/digit of a string at nth index using regex.
my string is a server name and can be a 10 - 11 character string like this.
$string = gfoobar9gac
i.e after 9g it can be any thing it can be a 10 characters or 11
I tried below options
if ("$string" =~ m/\w[8]g/i){
print "worked.\n";
} else {
print "Not worked\n";
}
m/\w[8]g/i
- Doesn't work
m/g*.1g.*/i
- works but if the string contains another 9g (gfoobar9g9g)it doesn't work and more specifically I only need the g at the index 8
/9g/
- This one fails too as there might 2 9g's in the string.
can someone please suggest something else using regex only.
Thanks,