我目前正在尝试在 js 中编写一个正则表达式,它将从混合字符串中提取十进制数。
示例字符串如下
mixed string123,456,00indeed
mixed string123,456.00indeed
mixed string123,4indeed
mixed string123,40indeed
mixed string 1,0
mixed string 1,00indeed
mixed string 1,00.00indeed
我想要的输出如下
123,456,00
123,456.00
123,4
123,40
1,0
1,00
1,00.00
如果我运行以下正则表达式
(\d+\,)+(.)+(\d+)
当小数点后跟一个数字时,它不会返回任何匹配项。例如。以下情况
mixed string123,4indeed
mixed string 1,0
我不确定如何调整适用于所有此类情况的正则表达式。如果有人可以请帮助我将非常有帮助。完整的js在这里
var str='mixed string123,4indeed';
str.match(/(\d+\,)+(.)+(\d+)/gm);
我也在 regex101 中得到这个,我不知道如何破译
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data