Eugen Konkov Eugen Konkov - 4 months ago 12
jQuery Question

Regex selector for jquery does not work. Why?

I am trying to use this but without success. I am on FFv47

I try to debug (F12) and stop script execution around the line:

return regex.test(jQuery(elem)[attr.method](attr.property));


When I enter watch expression:
jQuery(elem)[attr.method](attr.property)


I see
undefined


When I enter watch expression:
jQuery(elem)[attr.method]('class')


I see
'editor'
(as expected)

When I enter watch expression:
attr.property


I see
'class'


So I expect first watch expression to work and show me value
'editor'


Why
jQuery(elem)[attr.method](attr.property)
does not show me correct value?

Answer

At the specified blog post error. You should replace this:

regex = new RegExp(matchParams.join('').replace(/^s+|s+$/g,''), regexFlags);

by this (Notice \ near s+)

regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);

Also be carefull when you write selector:

$('script:regex( src,jQuery)');

If you occasionally put extra space as the example above the _src (count here _ as whitespace) property would be tested instead of expected src.

This also may be cause of error.