I’m trying to write a simple JavaScript function to remove all occurrences of a word with particular suffix in a string.
function removeClassBySuffix(s, suffix) {
var regx = new RegExp(what-regex-to-put-here, 'g');
s = s.replace(regx, '');
return s;
}
/* new RegExp('\\b.+?' + suffix + '\\b', 'g') -- doesn't work */
So,
removeClassBySuffix('hello title-edit-panel deal-edit-panel there', '-edit-panel');
// Should return 'hello there'.
Please help?
I have not tried it but I think the following should work:
new RegExp('\\b\\S+?' + suffix + '\\b', 'g')