Thursday, 9 February 2023

Regular expression for duplicate words

 

Regular expression for duplicate words

 

 

Try this regular expression:

\b(\w+)\s+\1\b

Here \b is a word boundary and \1 references the captured match of the first group.

Regex101 example here

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Blog Archive