Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could still use something like:</p> <pre><code>(^|,)bears(,|$) </code></pre> <p>It will look for the commas, or the beginning or end of the line, which I believe is what you're looking for.</p> <p><strong>EDIT: Addendum</strong></p> <p>Since Denomales mentioned it, the above regex search will consume any commas (if any) that it can find, so that you will get overlapping matches in the case of lists like <code>apples,orange,bears,honey,bears,bears,bears,bears,9999,bees</code> and will count only 3 bears out of the 5 present. What you can do in this case is use lookarounds. It might take a bit to get your head around them, but the gist of it is that they look behind, or ahead of characters without consuming them. This thus makes it possible to find all the 5 bears, and this is how you use them:</p> <pre><code>(?&lt;=^|,)bears(?=,|$) </code></pre> <p>A breakdown of characters...</p> <p><code>^</code> means the beginning of a line, so that in case there are no commas, you will still get a match.</p> <p><code>,</code> is a literal comma.</p> <p><code>(?&lt;= ... )</code> is a positive lookbehind and will look behind the <code>b</code> character in <code>bears</code> to make sure there is what's inside, that is either a <code>^</code> or a <code>,</code>.</p> <p><code>(?= ... )</code> is a positive lookahead and will look after the <code>s</code> character in <code>bears</code> to make sure there is what's inside, that is either a <code>,</code> or a <code>$</code>.</p> <p><code>$</code> means the end of a line, working very much like <code>^</code>, but at the end.</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