Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You escape it the way you escape most regex metacharacter: preceding with a backslash.</p> <p>Thus, <code>r"\[harry\]"</code> will match a literal string <code>[harry]</code>.</p> <p>The problem is with the <code>\b</code> in your pattern. This is the <em>word boundary anchor</em>.</p> <p>The <code>\b</code> matches:</p> <ul> <li>At the beginning of the string, if it starts with a word character</li> <li>At the end of the string, if it ends with a word character</li> <li>Between a word character <code>\w</code> and a non-word character <code>\W</code> (note the case difference)</li> </ul> <p>The brackets <code>[</code> and <code>]</code> are NOT word characters, thus if a string starts with <code>[</code>, there is no <code>\b</code> to its left. Any where there is no <code>\b</code>, there is <code>\B</code> instead (note the case difference).</p> <h3>References</h3> <ul> <li><a href="http://www.regular-expressions.info/wordboundaries.html" rel="nofollow noreferrer">regular-expressions.info/Word Boundaries</a></li> <li><a href="http://docs.python.org/library/re.html" rel="nofollow noreferrer">http://docs.python.org/library/re.html</a> <blockquote> <p><code>\b</code> : Matches the empty string, but only at the beginning or end of a word. A word is defined as a sequence of alphanumeric or underscore characters, so the end of a word is indicated by whitespace or a non-alphanumeric, non-underscore character. Note that <code>\b</code> is defined as the boundary between <code>\w</code> and <code>\W</code>, so the precise set of characters deemed to be alphanumeric depends on the values of the UNICODE and LOCALE flags. Inside a character range, <code>\b</code> represents the backspace character, for compatibility with Python’s string literals.</p> </blockquote></li> </ul>
 

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