1

I've trying to set up some filters from spam mail on our Microsoft Exchange server.

I need to check the letter ad spam if there is in header "Recieved" more then 3 dots and it doesn't containt word "outlook"

Checking dots can be done by regex .*\..*\..*\..*

Checking if string doesn't contain word "outlook" can be done by regex ((?!outlook).)*$

I try to unite then in one expression ^(?=.*\..*\..*\..*)(?=((?!outlook).)*$) but doesn't work:(

What am I doing wrong?

1 Answers1

1

You may use

^(?!.*outlook)[^.]*(?:\.[^.]*){0,2}$

See regex demo

Details

  • ^ - start of string
  • (?!.*outlook) - no outlook substring allowed anywhere on the line
  • [^.]* - any 0+ chars other than a .
  • (?:\.[^.]*){0,2} - 0, 1 or 2 occurrences of
    • \. - a dot
    • [^.]* - any 0+ chars other than a .
  • $ - end of string.

So, any string will be matched that has no outlook and that has 0, 1 or 2 dots only.

Note that in case you have multiple lines there, you will have to make . match multiple lines.

Wiktor Stribiżew
  • 484,719
  • 26
  • 302
  • 397