Since there have been so many examples of working rules ...

I thought I'd post the one that worked for me.
If you'll recall, I was looking to match any of the following words, anywhere in the subject line:
alpha
Alpha
ALPHA
Here's the expression I put together, that seems to work:
One of the keys I've found so far is, the php implementation wants delimiters around the expression.
In this case I used forward slash "\" (first and last characters in the expression above.)
Here is the blurb on that from the docs:
Quote:
|
The syntax for patterns used in these functions closely resembles Perl. The expression should be enclosed in the delimiters, a forward slash (/), for example. Any character can be used for delimiter as long as it's not alphanumeric or backslash (\). If the delimiter character has to be used in the expression itself, it needs to be escaped by backslash. Since PHP 4.0.4, you can also use Perl-style (), {}, [], and <> matching delimiters. See Pattern Syntax for detailed explanation.
|
So, in theory at least (haven't had a chance to test it) the following would/should work also:
Quote:
[\b[Aa]lpha\b|\bALPHA\b]
{\b[Aa]lpha\b|\bALPHA\b}
(\b[Aa]lpha\b|\bALPHA\b)
<\b[Aa]lpha\b|\bALPHA\b>
|
So, taking my little example apart:
- The "/" characters at the begining/end delimits the expression
- The \b tags before and after the text you're searching for tell regex to search on word boundaries (whole words) so it will match the strings I listed, but should skip other occurrences of alpha when it's part of another word (like "alphabet")
- The [Aa]lpha matches the strings "Alpha" or "alpha"
- The "|" is an "or" (match the string before the "|" or match the string after the "|"
- The last part simply matches "ALPHA" an all uppercase occurrence of alpha.
There is probably a more elegant way to do this, but I'm new to regex, so this is good enough for now I suppose.
HTH,
Rich
PS. The regex testers I've tried seem to choke on the word boundary and/or delimiter stuff.
PPS. I'm sure it would be helpful to the community if others posted creative examples they have found to work as well.
