<分区>
这是一个测验练习
使用替换在所有数字中放入逗号以分隔千位。即:12345678 → 12,345,678。数字可以在一个句子中,句子中可以有多个数字。
我试过代码
/(\d{3})(\d{3})/g
结果返回
Test 6/19: 100013541615681651 should become 100,013,541,615,681,651. Did you forget the global flag?
试过了
/\d(?=(?:\d{3})+(?!\d))/g
结果返回
Test 14/19: Your regex is incorrectly replacing the number in the following string: Your ticket number is A87654
正则表达式 demo
匹配的字符串
12345678901234567890
12345678
1234567
不匹配的字符串
A87654
预期结果
123,456789,012345,67890
123,45678
123,4567
A87654