[Solved] Perl regex for char ‘&’ [closed]


There must be an error somewhere else in your program.

This works as expected:

$s1 = 'M&M chocolates';
$s2 = 'Tom & Jerry';
printf("$s1\n") if $s1 =~ m/\w\W\w\s\w+/;
printf("$s2\n") if $s2 =~ m/\w+\s&\s\w+/;

outputs

M&M chocolates
Tom & Jerry

solved Perl regex for char ‘&’ [closed]