I am trying to write a regular expression that will detect a word that is repeated twice, e.g., greatgreat or appleapple. I could not find any way to do this, after hours of trying I am posting it here to see if anyone can help.
Try this (example on RegExr):
(\w+)\1
If you want to make sure that the whole sting is a doubled word add anchors:
^(\w+)\1$
For more information see the docs - "Round brackets for grouping and backreferences".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With