重复单词的正则表达式 [英] Regular Expression For Duplicate Words
本文介绍了重复单词的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一个正则表达式新手,我还不太清楚如何编写一个可以与任何重复的连续单词匹配"的正则表达式,例如:
I'm a regular expression newbie, and I can't quite figure out how to write a single regular expression that would "match" any duplicate consecutive words such as:
巴黎在春季.
不是与之相关的.
你为什么笑? 我的我的正则表达式不好吗?
Why are you laughing? Are my my regular expressions THAT bad??
是否有一个单个正则表达式将与上面的所有粗体字符串匹配?
Is there a single regular expression that will match ALL of the bold strings above?
推荐答案
尝试以下正则表达式:
\b(\w+)\s+\1\b
此处\b
是一个单词边界,\1
引用了捕获的第一组匹配项.
Here \b
is a word boundary and \1
references the captured match of the first group.
这篇关于重复单词的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文