tags:

views:

68

answers:

4

Hi all,

I'm getting strange kind of spam, where the email body only contains this:

4606142 5801100 2704743

How can I grep this with regex?

It's 3x7 numbers, separated with space.

thx

+4  A: 

Try this

(\d{7} ?){3}

or, if that whitespace makes a difference (just like Al said in comments)

(\d{7} ){2}\d{7}
Rubens Farias
Or `(\d{7} ){2}\d{7}` if you want to catch it when there's no ending space
Al
The ending space has been made optional with `?`
Amarghosh
A: 

Try this

[0-9]{7}\s[0-9]{7}\s[0-9]{7}

[0-9]{7}: 7 occurences of the characters '0' to '9'

\s: whitespace character

spa
A: 

You might want to capture arbitrary combinations of digits and whitespace:

^[\d\s]*$
soulmerge
A: 

Would this do? (\d{1,7}\s{0,})+

The reason I conclude the \s with a quantifier is it will fail when it reaches the end of the line where the last character after that may not be a space but a carriage return.

Hope this helps, Best regards, Tom.

tommieb75
also, why are you not using an external spam filter program to trap it, From Thunderbird for instance, you can click on the line that indicates Subject, Sender, Date and Time, there's a marker in there to mark that as spam by clicking on it, it is represented by what looks like to me an icon representing a flame. Thunderbird will remember next time. By the sound of it, it looks like you need to train your email client to recognise spam and take appropriate action instead of using regex.
tommieb75