Skip to content

24 ways to impress your friends

Vote up?

Jonathon Oates

Thanks for a fantastic essay tut!

One thing I found with your RegEx was that the whitespace (`s`) wasn’t escaped. I was trying with this for ages in Safari and Chrome (latest versions) and the RegEx would just never find a match in the `className` string.

I found double escaping the `s` special character worked a treat though ;-) as per: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp

So the RegEx I’ve ended up with (just for completeness) is:

var regEx = new RegExp(‘(\s|^)’ + activeClassName + ‘(\s|$)’);

Was this just a publishing error or should have your solution worked?

Thanks again,

Jon