问题
I am stuck at writing the regex which needs me to remove comma inside brackets. The commas outside should stay as is
Here's what I need
Input :(37.400809377128354, -122.05618455969392) , (37.3931723332768, -121.89276292883454)
Output :(37.400809377128354 -122.05618455969392) , (37.3931723332768 -121.89276292883454)
Thanks in Advance!
回答1:
You can use this regex which uses positive look ahead to discard matching a comma that is outside the parenthesis,
,(?=[^()]*\))
Demo
var s = "(37.400809377128354, -122.05618455969392),(37.3931723332768, -121.89276292883454)";
console.log(s.replace(/,(?=[^()]*\))/g, ''));
回答2:
ES '18 Solution using Look-behind Assertions
const s = "(37.400809377128354, -122.05618455969392),(37.3931723332768, -121.89276292883454)";
console.log(
s.replace(/(?<=\d),/g, '')
);
ECMAScript® 2018 Language Specification
来源:https://stackoverflow.com/questions/54359053/regex-for-removing-commas-within-brackets