Page 1 of 1

Findin only a 4 digit number?

Posted: Thu May 11, 2017 4:07 pm
by terrypin
I'm getting several spams a day with a subject that is simply a four digit number. So I want to construct a filter using regex that would take these subjects

abc 1278
1234
4321xyz
4567
abc6789def
abcd 6789 def


and delete only these two:
1234
4567

I will probably have to adapt it to suit my email program (Forte's Agent). But it would be a great help if someone could advise me how to get a regex expression that would find lines containing only a four digit number please.

Terry, East Grinstead, UK

Posted: Thu May 11, 2017 6:42 pm
by ben_josephs
If the numbers are alone on their lines:
^[0-9][0-9][0-9][0-9]$
or
^\d\d\d\d$
or
^[0-9]{4}$
or
^\d{4}$

If there might be trailing spaces:
^[0-9][0-9][0-9][0-9]\s*?$
etc.

Posted: Thu May 11, 2017 7:47 pm
by terrypin
Thanks so much, do appreciate the fast reply.

Terry, East Grinstead, UK