Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There seems to be a promise made in <a href="http://perldoc.perl.org/perlrequick.html" rel="nofollow noreferrer">perldoc perlrequick</a>:</p> <blockquote> <p>To match <code>dog</code> or <code>cat</code> , we form the regex <code>dog|cat</code> . As before, perl will try to match the regex at the earliest possible point in the string. At each character position, perl will first try to match the first alternative, <code>dog</code> . If <code>dog</code> doesn't match, perl will then try the next alternative, <code>cat</code> . If <code>cat</code> doesn't match either, then the match fails and perl moves to the next position in the string.</p> </blockquote> <p><a href="http://perldoc.perl.org/perlretut.html" rel="nofollow noreferrer">perldoc perlretut</a> seems to make the promise in an even stronger way (but with a caveat):</p> <pre><code>"cats" =~ /c|ca|cat|cats/; # matches "c" "cats" =~ /cats|cat|ca|c/; # matches "cats" </code></pre> <blockquote> <p>Here, all the alternatives match at the first string position, so the first alternative is the one that matches. If some of the alternatives are truncations of the others, put the longest ones first to give them a chance to match.</p> </blockquote> <pre><code>"cab" =~ /a|b|c/ # matches "c" # /a|b|c/ == /[abc]/ </code></pre> <blockquote> <p>The last example points out that character classes are like alternations of characters. At a given character position, the first alternative that allows the regexp match to succeed will be the one that matches.</p> </blockquote>
 

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