【发布时间】:2013-01-06 15:50:37
【问题描述】:
我有这个字符串,我试图将括号括在后面的数字数组中 “位置”和颜色。
str = 'Label_3_1:{位置:115,234,宽度:126,高度: 20,Text:"Another Button",FontSize: 18,Color: 0,0,0,1}'
我可以使用这个正则表达式来做到这一点,但前提是每个逗号后面的数字都有一个空格
str = str.replace(/([\d\.]+(, [\d\.]+)+)/g, "[$1]");
我正在尝试让它在没有任何空格的情况下工作。
输出应该是这样的
str = 'Label_3_1:{Position: 115,234,Width: 126,Height: 20,Text:"Another Button",FontSize: 18,Color: [0, 0, 0, 1] }'
【问题讨论】:
-
那个字符串是从哪里来的?如果可能,发送编码为 JSON 的字符串,然后在 JS 中解码。
标签: javascript regex string