Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have to escape the delimiter for qr//, and you have to escape any regex metacharacters that you want to use as literals. If you want those to be literal *'s, you need to escape them since the * is a regex quantifier.</p> <p>Your problem here is the various regex flags that you've added. The /m doesn't do anything because you don't use the beginning- or end-of-string anchors (^, $). The /s doesn't do anything because you don't use the wildcard . metacharacter. The /x makes all of the whitespace in your regex meaningless, and it turns that line with the # into a regex comment.</p> <p>This is what you want, with regex flags removed and the proper things escaped:</p> <pre><code>my $sc = qr{(&gt;|\s)}; my $re = qr{# using defaults found in \.config \* \* Options: $sc 1\. opt1 $sc 2\. opt2 choice\[1-2\?]: }; </code></pre> <p>Although Damian Conway tells people in <em>Perl Best Practices</em> to always put these options on their regexes, you now see why he's wrong. You should only add them when you want what they do, and you should only add things when you know what they do. :) Here's what you might do if you want to use /x. You have to escape any literal whitespace, you need to denote the line endings somehow, and you have to escape the literal # character. What was readable before is now a mess:</p> <pre> my $sc = qr{(>|\s)}; my $eol = qr{[\r\n]+}; my $re = qr{\# \s+ using \s+ defaults \s+ found \s+ in \s+ \.config $eol \* $eol \* $eol Options: $eol $sc \s+ 1\. \s+ opt1 $eol $sc \s+ 2\. \s+ opt2 $eol choice\[1-2\?]: \s+ }x; if ( $output =~ $re ) { print "OK!\n"; } else { print "D'oh!\n"; } </pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload