0

I'm trying to get the words in a string with repeated chars. For example: "II loooovve this video. It's awesooooommeee."

How can I get the result: loooovve awesooooommeee ?

2 Answers2

1

You can use this regex with a back-reference:

\b\w*(\w)\1\w*

RegEx Demo

RegEx Breakup:

\b     # word boundary
\w*    # match 0 or more word characters
(\w)   # match a single word char and capture it as group #1
\1     # back-reference to captured group #1 to make sure we have a *repeat*
\w*    # match 0 or more word characters

btw it will also match II since it has a repeating character I.

anubhava
  • 761,203
  • 64
  • 569
  • 643
0

Pattern for matching all words with 3+ repeated letters:

\b\w*(\w)\1{2}\w*

II loooovve this video. It's awesooooommeee.


https://regex101.com/r/cP7kT7/1

Maciej A. Czyzewski
  • 1,539
  • 1
  • 13
  • 24