Mintaka
Mintaka

Reputation: 21

Regex to match if word is included at least N times

Trying to create a SpamAssassin custom rule that matches if the phrase "SEO" is included in an email body four or more times.

Why doesn't a simple pattern like this match true?

/(SEO.*?){4,}/m

Upvotes: 2

Views: 1470

Answers (1)

Eric Duminil
Eric Duminil

Reputation: 54233

I think I got it. You don't need the "m" modifier, because you don't use either ^ or $. You need the "s" modifier, to allow use of . to match a newline character.

Your regex would be fine for finding a line containing 4 times SEO, but not for 2 lines each containing 2 SEO. See "Substitution Operator Modifiers" in http://www.tutorialspoint.com/perl/perl_regular_expression.htm

/(SEO.*?){4,}/s

Upvotes: 2

Related Questions