string - How to replace arbitrary groups of symbols in javascript with one single symbol? -
so have string looking so:
i+am++a+++great++coder how delete + in such way, 1 space remains in each instance? have tried using regex, no avail yet.
you can achieve desired result either splitting string @ every group of + , joining single whitespace
var str = 'i+am++a+++great++coder', res = str.split(/\++/g).join(' '); console.log(res); or replace every group of + single whitespace.
var str = 'i+am++a+++great++coder', res = str.replace(/\++/g, ' '); console.log(res);
Comments
Post a Comment