读书人

js正则轮换

发布时间: 2013-09-04 10:34:09 作者: rapoo

js正则替换
替换1.Is d is the cost of a of gasoline going up up?
要求匹配间隔一个之后的字符是否相同,如果相同就留第一个
要求匹配间隔一个之后的字符是否相同,如果相同就留第二个

举一反三
要求匹配间隔2个之后的字符是否相同,如果相同就留第二个
要求匹配间隔2的倍数个之后的字符是否相同,如果相同就留第二个 JavaScript 正则
[解决办法]

引用:
你的结果 d Is the cost a of gasoline going up
原始字符 Is d is the cost of a of gasoline going up up
虽然有差别
谢谢你提供思路,也请教下呢,找出第4个空格,怎么弄哦


//第4个空格替换成 ","
"Is d is the cost of a of gasoline going up up".replace(/(((^
[解决办法]
\s+)\S+){4})(\s)/,"$1,")

读书人网 >JavaScript

热点推荐