Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, I think I got it... These are the changes I made:</p> <ul> <li>The bottom five selectors have a capital "E" and should all be "containsRegex()"</li> <li><p>I changed the containsRegex a tiny bit by adding a "reg" check in the return, to make it more sturdy:</p> <pre><code>containsRegex: function(a,i,m){ var regreg = /^\/((?:\\\/|[^\/])+)\/([mig]{0,3})$/, reg = regreg.exec(m[3]); return reg ? RegExp(reg[1], reg[2]).test($.trim(a.innerHTML)) : false; } </code></pre></li> <li><p>All escaped characters in the regex need to be double escaped ( i.e. <code>\(</code> needs to be <code>\\(</code> )</p></li> <li><p>I removed all the single quotes to actually help me from being distracted</p></li> <li><p>I removed the class name numbers. I know ID's shouldn't start with numbers and I'm pretty sure class names shouldn't start or only be a number either. Anyway, this led to some selectors adding the same regex (i.e. "x" and "-" look the same, as well as "x*(mb)" and "X*(mb)" with the css in the demo).</p></li> </ul> <p>Anyway, I'll update my gist with this code and your <a href="http://jsfiddle.net/Mottie/w3C3Q/2/">demo</a>:</p> <pre><code>/* jQuery selector to match exact text inside an element * :containsExact() - case insensitive * :containsExactCase() - case sensitive * :containsRegex() - set by user ( use: $(el).find(':containsRegex(/(red|blue|yellow)/gi)') ) */ $.extend($.expr[':'],{ containsExact: function(a,i,m){ return $.trim(a.innerHTML.toLowerCase()) === m[3].toLowerCase(); }, containsExactCase: function(a,i,m){ return $.trim(a.innerHTML) === m[3]; }, containsRegex: function(a,i,m){ var regreg = /^\/((?:\\\/|[^\/])+)\/([mig]{0,3})$/, reg = regreg.exec(m[3]); return reg ? RegExp(reg[1], reg[2]).test($.trim(a.innerHTML)) : false; } }); // -, (mb), x*, x*(mb), x, x(mb), X*, X*(mb), X $("td:containsRegex(/^[xtfv]$/)").addClass("queue"); // x $("td:containsRegex(/^[xtfv]\\*$/)").addClass("queue review"); // x* $("td:containsRegex(/^\\([a-z]{2}\\)$/)").addClass("active"); // (mb) $("td:containsRegex(/^[xtfv]\\([a-z]{2}\\)$/)").addClass("active"); // x(mb) $("td:containsRegex(/^[xtfv]\\*\\([a-z]{2}\\)$/)").addClass("active review"); // x*(mb) $("td:containsRegex(/^[XTFV]$/)").addClass("done"); // X $("td:containsRegex(/^[XTFV]\\*$/)").addClass("queue review"); // X* $("td:containsRegex(/^[XTFV]\\*\\([a-z]{2}\\)$/)").addClass("active review"); // X*(mb) $("td:containsExact(-)").addClass("queue"); // - </code></pre>
    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. 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.
 

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