This will ensure that the string is exactly six characters, only consists of alpha-num, and matches the 5th char:
use warnings; use strict; my $str = 'xpy7pG'; my $char = 'p'; if ($str =~ /^\w{4}$char\w$/){ print "matched\n"; }
update: I lied. The above will also match an underscore (as \w matches [a-zA-Z0-9_]. If you don't want that, you can use this:
/^[0-9A-Za-z]{4}$char[0-9A-Za-z]$/
In reply to Re: Perl RegEx doubt
by stevieb
in thread Perl RegEx doubt
by swissknife
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |