Got this string:
'test',$, #207
I need to remove spaces which have a commma before
So the result will be: 'test',$,#207
Tried this:
replace(/\/s,]/g, ',')
Not working. Any ideas?
Got this string:
'test',$, #207
I need to remove spaces which have a commma before
So the result will be: 'test',$,#207
Tried this:
replace(/\/s,]/g, ',')
Not working. Any ideas?
To replace only spaces and not other whitespaces use the following regex.
Regex: /, +/g
Explanation:
, will search for comma.
+ will search for multiple spaces.
And then replace by , using replace(/, +/g, ',')
I need to remove spaces which have a commma afterwards
No, your example says the opposite. That is, you want to remove spaces that have a comma before them.
In either case, the error in your expression is the "]".
replace(/\/s,/g, ',')
Does what you say you want to do, and
replace(/,\/s/g, ',')
Does what the example says.
The other answer is right, though - just use replace(' ,', ''); you need no regex here.
I think you meant comma that have whitespace afterwards:
stringVar = "'test',$, #207";
replace('/\,\s/g', stringVar);
\, means , literally and \s means whitespace.
You can test javascript regex and know a little more about the modifiers and stuff at regex101.
replace(new RegExp(find, ', '), ',');