Home > front end >  Regex - Find string that has 5 or more mentions in it
Regex - Find string that has 5 or more mentions in it

Time:01-12

Trying to detect whether a message has 5 or more mentions in it. For example:

"@Boddy is doing great with @shirly @rebecca @jimmy and @mom"

Above will count as one match. This will not count as a match:

"@Boddy is doing great with @shirly @rebecca @jimmy and ..."

Preferably, "@@@@@" should not count either, but not too important!

I've tried

@([^@ ] ){5,}

But no luck, it highlights all 5 instead of the whole string.

CodePudding user response:

Use a pattern which covers the entire string:

^.*@.*@.*@.*@.*@.*$

Demo

  •  Tags:  
  • Related