【发布时间】:2021-11-29 17:14:11
【问题描述】:
我试图创建一个可以匹配括号内数字的正则表达式,例如:
(1.000.000,00) //match
(1.000,00) //match
(100,00) //match
(10) //match
(1) //match
(2.000.000,00 //dont't match
(2.000,00 //dont't match
(200,00 //dont't match
(20 //dont't match
(2 //dont't match
3.000.000,00) //dont't match
3.000,00) //dont't match
300,00) //dont't match
30) //dont't match
3) //dont't match
4.000.000,00 //should match
4.000,00 //should match
400,00 //should match
40 //should match
4 //should match
我只需要匹配数字(是否在括号中),但前提是它们包含所有括号 (2) 或没有 (0)
目前这是我想出的:\((\d+[\.,]?)+\d*\),它匹配 --match 而不匹配 --don't match但也应该匹配 --should match
我添加了javascript 标签,因为我在 js 中使用了这个正则表达式,并不是所有的正则表达式标记都可以在 js 正则表达式构造函数中工作
我还发布了一个 regex101 link
【问题讨论】:
标签: javascript regex