Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Even though <code>\Z</code> and <code>$</code> only match at the end of the string (when the option for the caret and dollar to match at embedded line breaks is off), there is one exception. If the string ends with a line break, then <code>\Z</code> and <code>$</code> will match at the position before that line break, rather than at the very end of the string. </p> <p>This "enhancement" was introduced by Perl, and is copied by many regex flavors, including Java, .NET and PCRE. In Perl, when reading a line from a file, the resulting string will end with a line break. Reading a line from a file with the text "joe" results in the string joe\n. When applied to this string, both <code>^[a-z]+$</code> and <code>\A[a-z]+\Z</code> will match "joe".</p> <p>If you only want a match at the absolute very end of the string, use <code>\z</code> (lower case z instead of upper case Z). <code>\A[a-z]+\z</code> does not match joe\n. <code>\z</code> matches after the line break, which is not matched by the character class.</p> </blockquote> <p><a href="http://www.regular-expressions.info/anchors.html" rel="noreferrer">http://www.regular-expressions.info/anchors.html</a></p> <p>The way I read this <code>"StackOverflow\n".matches("StackOverflow\\z")</code> should return false because your pattern does not include the newline.</p> <pre><code>"StackOverflow\n".matches("StackOverflow\\z\\n") =&gt; false "StackOverflow\n".matches("StackOverflow\\Z\\n") =&gt; true </code></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