Page 1 of 2

regex question - symbol for "and"

Posted: Sun Aug 08, 2010 2:49 am
by allangjohnson
I know that a | is used for "or" in a regex expression as in yes|no but what is the symbol for "and"?

Thanks.
AJ

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 2:52 am
by anniebrion
Everything that is not an or (|) is an and.

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 2:55 am
by allangjohnson
That was quick - thanks.

So, if I write

(.+@){10,} [email protected]

that would catch anything that was both sent to ten or more recipients AND was from [email protected]?

AJ

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 3:01 am
by anniebrion
The from: test would go in a separate rule and set the rules to ALL instead of ANY.

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 3:03 am
by allangjohnson
That's what I was hoping to avoid, because I wanted that filter to be one line in a multiline filter that would be tripped in ANY condition was satisfied.

AJ

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 3:11 am
by anniebrion
It's difficult testing to: & from: in the same single rule as I have tried to do this in the past :(

The major issue is that email headers are not standardized enough, sometimes the to: comes before the from: other times it is the reverse, also sometimes a subject: is inbetween and sometimes not :(

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 3:16 am
by allangjohnson
I understand. But am I correct that just putting a space between the two items makes it an "AND"?
So, using a different example, if the filter looks in the subject line for

hot cold

it would trip only if the subject line contained both words?

AJ

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 3:22 am
by anniebrion
NO putting a space is not an AND.

The and is ie:

Code: Select all

.+@domain
"1 or more characters" AND @ AND domain

Code: Select all

(fred|bert)@domain
(fred OR fred) AND @ AND domain

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 3:28 am
by allangjohnson
Sorry to be so slow, but why isn't

(fred|bert)@domain)

(fred OR fred) AND @ AND d AND o AND m AND a AND i AND n?

AJ

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 3:32 am
by anniebrion
It is but I couldn't be bothered to do all the ANDs :devil and it looks tidier than:

"1 or more characters" AND @ AND d AND o AND m AND a AND i AND n

Or

((f AND r AND e AND d) OR (b AND e AND r AND t)) AND @ AND d AND o AND m AND a AND i AND n

The last one makes the AND and ORs harder to spot.

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 4:11 am
by allangjohnson
So there isn't a way to have a single line that trips a filter if the subject line contains

hot AND cold

AJ

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 4:15 am
by anniebrion
allangjohnson wrote:So there isn't a way to have a single line that trips a filter if the subject line contains

hot AND cold

AJ
Yes there is but they have to be in the right order or you will need 2 rules

Code: Select all

hot\x20.*cold

Code: Select all

cold\x20.*hot
.* = Zero or more characters
\x20 = Space

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 4:18 am
by allangjohnson
or could it be in a single line as

hot.*cold|cold.*hot

?

AJ

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 4:21 am
by anniebrion
allangjohnson wrote:or could it be in a single line as

hot.*cold|cold.*hot
Simplistically yes, but that would match subject = "Hotdogs and coldfish"

Mabye:

Code: Select all

hot(\x20|$).*cold(\x20|$)|cold(\x20|$).*hot(\x20|$)
But I'm sure you get the idea.

Re: regex question - symbol for "and"

Posted: Sun Aug 08, 2010 4:24 am
by allangjohnson
I think I've got it. Thank you.

AJ