Fadeoc Khaos Fadeoc Khaos - 2 years ago 114
Javascript Question

Regex match the last part of a string

I want to add CSS reference dynamically by 'onclick' event, and filter serveral CSS references with different names but all ended with 'a', my plan is using Regex.

if (cssRef != /.*a.css$/){
then add the css reference

which is not working, Thanks for your time.

Answer Source

It will not work this way. You need to call method:

if (!(/.*a\.css$/).test(cssRef)) { ... }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download