in reply to Regex Start Anchor with variables
Hi chrism01, use Quotemeta "\Q & \E".
if( $str1 =~ /^\Q$str2\E/ ) { print "match\n"; } else { print "nomatch\n"; }
Updated
See the documentation in perldoc as quotemeta
In string2 $str2 = ".1.2.3.4";, dots(.) are present and it will be treated as any character except new line in regular expression. So dots should be escaped using "\Q".
Regards,
Velusamy R.
|
|---|