I'm trying to use regex inside if. Strange, but it doesn't work. How it may be fixed?
It works:
var lang = 'lang-js'; if (lang == 'lang-js') { alert('ok'); } It works too (just for testing purposes):
var lang = 'lang-js'; if (lang == 'lang-' + 'js') { alert('ok'); } But this one doesn't work:
var lang = 'lang-js'; if (lang == 'lang-' + /[a-z]/) { alert('not ok'); }
'lang-' + /[a-z]/in the browser console and see what happens. You're not doing a regular expression test, you are concatenating a regex with a string, which produces a string, and then comparing that with another string. This has nothing to do with jQuery so I've removed that tag.