Findin only a 4 digit number?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
terrypin
Posts: 174
Joined: Wed Jul 11, 2007 7:50 am

Findin only a 4 digit number?

Post 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
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post 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.
terrypin
Posts: 174
Joined: Wed Jul 11, 2007 7:50 am

Post by terrypin »

Thanks so much, do appreciate the fast reply.

Terry, East Grinstead, UK
Post Reply