Regular Expression For Duplicate Words

后端 未结 13 1991
终归单人心
终归单人心 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条回答
  •  日久生厌
    2020-11-22 11:59

    The widely-used PCRE library can handle such situations (you won't achieve the the same with POSIX-compliant regex engines, though):

    (\b\w+\b)\W+\1
    

提交回复
热议问题