I’m trying to replace all spaces within a string with hyphens. I tried this: h3Text.replace(/\s/, '-'); But it only replaces the first instance of a space and not the ones after
Solution 1:
try
h3Text.replace(/\s/g, '-');
the g flag is key here. it means global replace, ie replace all
Share
Post a Comment
for "How To Make This Regex Replace Work On All Characters, Not Just The First?"
Post a Comment for "How To Make This Regex Replace Work On All Characters, Not Just The First?"