Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Assuming <strong><em>there are no nested brackets</em></strong>, you can use the following regex to search for the text:</p> <pre><code>(?i)\((?=[^()]*(?:dj|mix|version|inch))([^()]+)\) </code></pre> <p>Note that the regex is <strong>case-insensitive</strong>, due to <code>(?i)</code> in front - make it <em>case-sensitive</em> by removing it.</p> <p>Check the syntax of your language to see if you can use <code>r</code> prefix, e.g. <code>r'literal_string'</code>, to specify literal string.</p> <p>And use the following as replacement:</p> <pre><code>[$1] </code></pre> <p>You can include more keywords by adding keywords to <code>(?:dj|mix|version|inch)</code> part, each keyword separated by <code>|</code>. If the keyword contains <code>(</code>, <code>)</code>, <code>[</code>, <code>]</code>, <code>|</code>, <code>.</code>, <code>+</code>, <code>?</code>, <code>*</code>, <code>^</code>, <code>$</code>, <code>\</code>, <code>{</code>, <code>}</code> you need to escape them (I'm 99% sure the list is exhaustive). An easier way to think about it is: if the keyword only contains space and alphanumeric (but note that the number of spaces is strict), you can add them into the regex without causing side-effect.</p> <hr> <p>Dissecting the regex:</p> <ul> <li><p><code>(?i)</code>: <strong>Case-insensitive</strong> mode</p></li> <li><p><code>\(</code>: <code>(</code> is special character in regex, need to escape it by prepending <code>\</code>.</p></li> <li><p><code>(?=[^()]*(?:dj|mix|version|inch))</code>: Positive look-ahead <code>(?=pattern)</code>:</p> <ul> <li><p><code>[^()]*</code>: I need to check that the text is within bracket, not outside or in some other bracket, so I use a negated character class <code>[^characters]</code> to avoid matching <code>()</code> and spill outside the current bracket. The assumption I made also comes into play a bit here.</p></li> <li><p><code>(?:dj|mix|version|inch)</code>: A list of keywords, in a <em>non-capturing group</em> <code>(?:pattern)</code>. <code>|</code> means alternation.</p></li> </ul></li> <li><p><code>([^()]+)</code>: The assumption about no nested bracket makes it easier to match all the characters inside the bracket. The text is <em>captured</em> for later replacement, since <code>(pattern)</code> is capturing group, as opposed to <code>(?:pattern)</code>.</p></li> <li><p><code>\)</code>: <code>)</code> is special character in regex, need to escape it by prepending <code>\</code>.</p></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