I am using the jQuery " contains " extension as shown below:
$.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 RegExp(reg[1], reg[2]).test($.trim(a.innerHTML)); } });
I have a table with specific cells that I am trying to format conditionally, so I use the extension in the td
selector using the containsRegex
function. The problem I am facing is that many of the regular expressions I am trying to use (which I tested on regex javascript testers such as this and they worked) do not work with this function. These are the various lines that I would like to match:
Note that “x” can be ax, t, f, or v, and “X” can be X, T, F, or V. Finally, “(mb)” can be any two lowercase letters az in parenthesis.
-, (mb), x *, x * (mb), x, x (mb), X *, X * (mb), X
And here is the code with several regex statements that I use:
$("td:containsExact('-')").addClass("0 queue"); // - $("td:containsRegex('/[^xtfv*]\([az]{2}\)/g')").addClass("1 active"); // (mb) $("td:containsRegex('/\b[xtfv]\*(?!\()/g')").addClass("2 queue review"); // x* $("td:containsRegex('/\b[xtfv]\*(?:\([az]{2}\))/g')").addClass("3 active review"); // x*(mb) $("td:containsRegEx('/\b[xtfv](?![*\(])/g')").addClass("4 queue"); // x $("td:containsRegEx('/\b[xtfv](?:\([az]{2}\))/g')").addClass("5 active"); // x(mb) $("td:containsRegEx('/\b[XTFV]\*(?!\()/g')").addClass("6 queue review"); // X* $("td:containsRegEx('/\b[XTFV]\*(?:\([az]{2}\))/g')").addClass("7 active review"); // X*(mb) $("td:containsRegEx('/\b[XTFV](?![*\(])/g')").addClass("8 done"); // X
Most of them skip errors in Chrome. Does anyone have pointers? Is the extension restriction somehow limited?
Thanks in advance for your help!
mbeasley
source share