Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think I first saw this idea in... Jinja2's source code? Later transplanted it to Mako.</p> <pre><code>r'''(\"\"\"|\'\'\'|\"|\')((?&lt;!\\)\\\1|.)*?\1''' </code></pre> <p>Which does the following:</p> <ul> <li><code>(\"\"\"|\'\'\'|\"|\')</code> matches a Python opening quote, because this happens to be taken from code for parsing Python. You probably don't need all those quote types.</li> <li><code>((?&lt;!\\)\\\1|.)</code> matches: EITHER a matching quote that was escaped ONLY ONCE, OR any other character. So <code>\\"</code> will still be recognized as the end of the string.</li> <li><code>*?</code> non-greedily matches as many of those as possible.</li> <li>And <code>\1</code> is just the closing quote.</li> </ul> <p>Alas, <code>\\\"</code> will still incorrectly be detected as the end of the string. (The template engines only use this to check if there <em>is</em> a string, not to extract it.) This is a problem very poorly suited for regular expressions; short of doing insane things in Perl, where you can embed real code inside a regex, I'm not sure it's possible even with PCRE. Though I'd love to be proven wrong. :) The killer is that <code>(?&lt;!...)</code> has to be <em>constant-length</em>, but you want to check that there's any <em>even</em> number of backslashes before the closing quote.</p> <p>If you want to get this correct, and not just mostly-correct, you might have to use a real parser. Have a look at <a href="http://pypi.python.org/pypi/Parsley" rel="noreferrer">parsley</a>, <a href="http://pyparsing.wikispaces.com/" rel="noreferrer">pyparsing</a>, or <a href="http://nedbatchelder.com/text/python-parsers.html" rel="noreferrer">any of these tools</a>.</p> <p>edit: By the way, there's no need to check that the <em>opening</em> quote doesn't have a backslash before it. That's not valid syntax outside a string in JS (or Python).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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