global=global.toString().replace(/(\d+),,,(?=\d)/g, '$1,.');
I am replacing the commas here. I need to replace the commas in between a positive and the second a negative number.
I am replacing the commas here. I need to replace the commas in between a positive and the second a positive or negative number.
How do I do both of these?
For example
const global = '1,-1,2,4,-2';
global.replace(/(-?\d+),(?=-?\d+)/g, '$1,.');
will output
'1,.-1,.2,.4,.-2'
So, you just need to add -? in your expression to indicate it is possible to be positive or negative.