I've got a tricky piece of regex I need help with.
I have a string(s):
used inventory/ford/focus/lx
used-inventory/ford/focus
aboutus/ourteam/andy matthews
All of which need to have non alpha-numeric characters removed (barring dashes, and ONE slash, the first one). Given that, the above strings would need to be converted to:
used-inventory/ford-focus-lx
used-inventory/ford-focus
aboutus/ourteam-andy-matthews
The JS I'm using atm:
var regex = /[^a-zA-Z0-9/-]/gi;
var str = 'used inventory/ford/ding/dong';
var final = str.replace(regex,'-');
console.log(final);
Can anyone help out?




Bookmarks