Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Why does <code>[^\1]+</code> instead of <code>[^"]+</code> make RegExp greedy?</p> </blockquote> <p>That isn’t what you think it is doing. </p> <p>First of all, a <code>+</code> is <em>always</em> a <strong>maximal match</strong>, the thing you are calling “greedy”. It’s <code>+?</code> which is a <strong>minimal match</strong>.</p> <p>Second and more importantly, back‐referencing doesn’t happen in square‐bracketed character classes. You have accidentally just asked for any character except for Control‑A. That’s because backslash followed by digits means that code point in octal notation, as in <code>\177</code> for <code>DELETE</code> ᴀᴋᴀ <code>\x7F</code>, or <code>\40</code> for SPACE ᴀᴋᴀ <code>\x20</code>, or <code>\0</code> for NULL . So when you wrote <code>\1</code>, you have just used U+0001 or <code>\x01</code>. Don’t do that. :)</p> <p>You probably mean to use</p> <pre><code>(["'])(?:(?!\1).)+\1 </code></pre> <p>instead. You’ll need <code>/s</code> mode so that dot can match newlines, which I seem to recall Javascript has some screwed‐up–ness with.</p> <hr> <p><strong>EDIT:</strong> According to <a href="http://www.regular-expressions.info/dot.html" rel="nofollow">this</a>, clumsy old Javascript has no way to make dot match linebreaks. What rimnods! And of course because Javascript can’t do Unicode regexes, you can’t use the <code>\p{Any}</code> required by <a href="http://unicode.org/reports/tr18/#Categories" rel="nofollow">UTS#18’s RL1.2</a>. </p> <p>That means you’ll have to use some lame kludge like <code>[\S\s]</code> instead if there’s a chance that you might have linebreaks in your quoted strings.</p>
 

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