用于删除括号内逗号的正则表达式 [英] Regex for removing Commas within brackets

查看:55
本文介绍了用于删除括号内逗号的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在编写需要我删除括号内逗号的正则表达式.外面的逗号应该保持原样

I am stuck at writing the regex which needs me to remove comma inside brackets. The commas outside should stay as is

这是我需要的

输入:(37.400809377128354, -122.05618455969392), (37.3931723332768, -121.89276292883454)

Input :(37.400809377128354, -122.05618455969392) , (37.3931723332768, -121.89276292883454)

输出 :(37.400809377128354 -122.05618455969392) , (37.3931723332768 -121.89276292883454)

Output :(37.400809377128354 -122.05618455969392) , (37.3931723332768 -121.89276292883454)

提前致谢!

推荐答案

您可以使用这个正则表达式,它使用正向预测来丢弃括号外的匹配逗号,

You can use this regex which uses positive look ahead to discard matching a comma that is outside the parenthesis,

,(?=[^()]*\))

演示

var s = "(37.400809377128354, -122.05618455969392),(37.3931723332768, -121.89276292883454)";
console.log(s.replace(/,(?=[^()]*\))/g, ''));

这篇关于用于删除括号内逗号的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆