Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see that you've already found a solution that works, but I thought it might be worthwhile to explain what the problem with your original regex is.</p> <ul> <li><code>(?&lt;=\{)</code> means that a <code>{</code> must precede whatever matches next. Fair enough.</li> <li><code>((?!{).*?)</code> will match anything that starts with a character other than <code>{</code>. Okay, so we're only matching things <em>inside</em> the braces. Good.</li> </ul> <p>But now consider what happens when you have two opening braces: <code>{{bar}}</code>. Consider the substring <code>bar</code>. What precedes the <code>b</code>? A <code>{</code>. Does <code>bar</code> start with <code>{</code>? Nope. So the regex will consider this a match.</p> <p>You have, of course, prevented the regex from matching <code>{bar}</code>, which is what it would do if you left the <code>(?!{)</code> out of your pattern, because <code>{bar}</code> starts with a <code>{</code>. But as soon as the regex engine determines that no valid match starts on the <code>{</code> character, it moves on to the next character--<code>b</code>--and sees that a match starts there.</p> <p>Now, just for kicks, here's the regex I'd use:</p> <p><code>(?!&lt;={){([^{}:]+)[}:](?!=})</code></p> <ul> <li><code>(?!&lt;{)</code> : the match shouldn't be preceded by <code>{</code>.</li> <li><code>{</code> : the match starts with an open brace.</li> <li><code>([^{}:]+)</code> : <strong>group</strong> everything that isn't an open-brace, close-brace, or colon. This is the part of the match that we actually want.</li> <li><code>[}:]</code> : end the match with a close-brace or colon.</li> <li><code>(?!})</code> : the match shouldn't be followed by <code>}</code>.</li> </ul>
    singulars
    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.
 

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