[英]How to Organize Numbers using Regular Expression/Javascript
I would like to a regular expression to use with javascript replace function that separe with a space each 2 number I type 我想将正则表达式与javascript替换函数一起使用,该函数用键入的每2个数字分隔一个空格
Input Ex.: 01020304050607 输入示例:01020304050607
Output Ex.: 01 02 03 04 05 06 07 输出示例:01 02 03 04 05 06 07
How could I do it? 我该怎么办?
/(\\d{2})/g
should do the trick. /(\\d{2})/g
应该可以解决问题。 Example: 例:
> "021651984984984984".replace(/(\d{2})/g, "$1 ").trim()
"02 16 51 98 49 84 98 49 84"
Something like this? 像这样吗
var numbers = "0203040506";
var numbersString = numbers.replace(/([0-9]{2})(?=.)/g,"$1 ");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.