문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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}\.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top