Regular Expression For Duplicate Words

后端 未结 13 1986
终归单人心
终归单人心 2020-11-22 11:13

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

13条回答
  •  萌比男神i
    2020-11-22 12:13

    I believe this regex handles more situations:

    /(\b\S+\b)\s+\b\1\b/
    

    A good selection of test strings can be found here: http://callumacrae.github.com/regex-tuesday/challenge1.html

提交回复
热议问题