I have two replace methods called on a string, and I know they can be combined. I would like to know how to combine the two expressions, why, and maybe links to more information
var key = templateKey.replace(/:/g, '').replace(/\//g,'')
I have two replace methods called on a string, and I know they can be combined. I would like to know how to combine the two expressions, why, and maybe links to more information
var key = templateKey.replace(/:/g, '').replace(/\//g,'')
Well, Dr. Google can give you lots of links for more information on regular expressions, but in this case you're just replacing either a colon (:) or a slash (/), so you could combine them using the OR (|) grouping:
/(:|\/)/
var key = templateKey.replace(/[:\/]/g, '');