Fadeoc Khaos Fadeoc Khaos - 1 year ago 71
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