且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JavaScript正则表达式删除特定的连续重复字符

更新时间:2023-02-21 15:20:42

正则表达式是 / [^ \\\\ t] |(。) \ 1 / gi

在此测试: http://jsfiddle.net/Cte94/

它使用反向引用来搜索任何字符(。)后跟相同的字符 \1

it uses the backreference to search for any character (.) followed by the same character \1

除非检查重复的字符你的意思是 aaa => a

Unless by "check for duplicate characters" you meant that aaa => a

然后它是 / [^ \\\\ t] |(。)(?= \ 1)/ gi

在此测试: http://jsfiddle.net/Cte94/1/

请注意,两个正则表达式都不区分大小写。 A == a ,所以 Aa 是重复。如果您不想要它,请从 / gi

Be aware that both regexes don't distinguish between case. A == a, so Aa is a repetition. If you don't want it, take away the i from /gi