Question

We are getting a lot of spam in the form femlmcte@tnbt.com.

I can see cPanel Spam assassin allows a regex match to be used to filter mail.

I want to write a regex expression that identifies mail in the form

anylengthofstrring@abcd.com  

or

someotherlength@efgh.co.za

i.e ONLY four letters after the @, but before the .com, .co.uk, .co.za etc

Was it helpful?

Solution

Try the following:

[^@]+@[a-zA-Z]{4}\.(com|co\.uk|co\.za)

Explanation:

[^@]+@                # One or more characters except @ followed by @
[a-zA-Z]{4}           # Matches 4 characters in the range A-Z and a-z
\.(com|co\.uk|co\.za) # Matches .com, .co.uk, and .co.za

If you want to match any tld, replace (com|co\.uk|co\.za) with .* (I'm assuming that since you are receiving these e-mails, you already know they are valid, so no need to validate the TLD).

Also note that with your current criteria, you'd consider as spam something from admin@food.com, which may or may not be what you want.

OTHER TIPS

So you want to match an at-sign followed by 4 non-dot characters, followed by a dot? This specification translates easily into a regexp:

@[^.]{4}\.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top