Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason you get <code>note</code> is <a href="http://www.regular-expressions.info/brackets.html" rel="nofollow">capturing</a>. Sets of parentheses make that part of the match available later (or within backreferences). Since you don't even need the parentheses for grouping, just remove them, if you don't want <code>note</code>.</p> <p>Then your spaces are optional (due to the <code>?</code>) - hence, removing them in the string does not matter at all. Simply remove the <code>?</code> or make it a <code>+</code> (so that more than one space is allowed).</p> <p>The other problem is, that <code>.</code> can match spaces as well. You should maybe be a bit more restrictive (this way you can also avoid ungreedy quantifiers, which are generally worse in performance):</p> <pre><code>/&lt;!ELEMENT\s+\S*\s+\([^)]*\)&gt;/i </code></pre> <p><code>\S</code> matches anything except space character and <code>[^)]</code> matches anything except <code>)</code> characters (it's a negated character class). In fact, you might want to exclude <code>(</code> from the <code>\S</code> as well, because otherwise it could already match into the parentheses:</p> <pre><code>/&lt;!ELEMENT\s+[^\s(]*\s+\([^)]*\)&gt;/i </code></pre> <p>If the <code>note</code> part has to contain at least one character you should make that clear in the regex as well, by using <code>+</code> instead of <code>*</code></p> <pre><code>/&lt;!ELEMENT\s+[^\s(]+\s+\([^)]*\)&gt;/i </code></pre> <p>If the <code>note</code> part is optional on the other hand, my earlier version requires at least <strong>2</strong> spaces (due to the two <code>\s+</code>). In that case, you could group the <code>note</code> part along with the following space and make it optional together. This way you only require the space, if <code>note</code> is there. To suppress capturing (so you don't get two strings again), use <code>(?:...)</code> for grouping instead of <code>(...)</code>:</p> <pre><code>/&lt;!ELEMENT\s+(?:[^\s(]+\s+)?\([^)]*\)&gt;/i </code></pre> <p>Note that <code>match</code> will still give you an array containing the string you are looking for (and you can't do anything about that), so you'll have to access it with <code>[0]</code>.</p>
    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.
    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