I'm having a hard time determining what characters must be escaped when using Perl's qr{} construct
I'm attempting to create a multi-line precompiled regex for text that contains a myriad of normally escaped characters (#*.>:[]) and also contains another precompiled regex. Additionally I need to match as strictly as possible for testing purposes.
my $output = q{# using defaults found in .config
*
*
Options:
1. opt1
> 2. opt2
choice[1-2?]: };
my $sc = qr{(>|\s)}smx;
my $re = qr{# using defaults found in .config
*
*
Options:
$sc 1. opt1
$sc 2. opt2
choice[1-2?]: }mx;
if ( $output =~ $re ) {
print "OK!\n";
}
else {
print "D'oh!\n";
}
Error:
Quantifier follows nothing in regex; marked by <-- HERE in m/# using defaults found in .config
* <-- HERE
*
Options:
(?msx-i:(>|\s)) 1. opt1
(?msx-i:(>|\s)) 2. opt2
choice[1-2?]: / at ./so.pl line 14.
Attempting to escape the asterisks results in a failed match (D'oh output). Attempting to escape other pesky chars also results in a failed match. I could continue trying different combos of what to escape, but there's a lot of variations here and am hoping someone could provide some insight.