regex / heuristic to detect repetitive junk words like "gfgfgfgf" "dadadada" "sdsdsd" etc : searching for this solution proved to be a bit hard to find, so I'm forced to ask the question.

**First, a bit of a background story:**

- I run a blog
- I have a post about **reCaptcha**
- Sometimes (every week or so) someone tries to be funny and posts spam comments in the similar form to this:

>gfgfgfgf

>sdsdsdsds

>dadadada

You get the idea. Are they testing an automated reCaptcha bypass systems as a proof of concept or just trying to be funny, I don't know and I don't really care (most probably a mix of both).

(edit) Interestingly enough, no other posts are affected by this type of spam comments.

However, thinking about this, it should be relatively simple and easy to detect patterns in the (mostly) single words which those comments have (99%) and prevent those comments from posting. Sounds simple?

But, it must also be good enough to avoid false positives.

If, for example, a comment has single repetitive word like above, then it's definitely a spam.

If, on the other hand, it just has a typo in the middle of the normal sentence, it should pass.

Now, I can already 'hear' comments below why not use Akismet. Or solution X. Or solution Y. Why not external comments system like **Disqus** or **Facebook comments**. Because, I can't. It must be in-house. And I wish to be simple. I already have some things that prevent a lot of junk, but for this particular case they all fail.

**Solution(s) that I have tested so far:**

This is one regex example that is a variant of this answer [here][1], but it's not perfect:

    (.+\w)(?=\1+)/gu

**[see live regex101 example][2]**

Problems with it is that in examples below it will pass most of the time, but it will trigger false positives, too:

correct/proper detection:

> 123123123123

> daddaddaddad

> sadsadasad

> sadsadsad

> 121212121

> sasasasasas

> sdsdsdsds

> dsdsdsdsd

> ffffffff

> blahblah

> ioiooioioioi

> popopopopop

> Hi I dont think this is a spam.

improper/incorrect detection (false positive):

> I loooovve this. It's awesooooommeee!

Now, this is tricky. The filter does exactly what it was instructed to do, however, "ooovv" and "oooommeee" patterns are not exactly repetitive in the same sense like the first ones listed above ("gfgfgfgf" etc.) - filter detect "oo" pattern repetition. Yes, it is correct, but not exactly what I want to target.

Does anyone have an idea how can I improve this regex detection to be smarter a bit?

One thought / idea that I have is outside of the regex itself, and that is to let pass single repetitions IF comment contains more than 1 word (e.g. something closer to a full sentence). But, I'd like the case where actual repetition can be differentiated, such as in the case of "awesoooommeee" word.

Thanks!


  [1]: https://stackoverflow.com/a/943924/2715309
  [2]: https://regex101.com/r/6k0Fiz/1