Link to home
Start Free TrialLog in
Avatar of rito1
rito1

asked on

Regular expression match words - ignores OR

Hi All,

In C# I have the following variable that tests for the following matches... ' not ',' and ',' or '.

This seems to work fine when locating matches for ' not ' and ' and ' but it doesn't work when locating the keyword ' or '.

Can anyone see what I am doing wrong?

Match matchBoolOperators = Regex.Match(strSearchTerm.ToLower(), @"[ not ][ and ][ or ]");

Open in new window


Many thanks,

Rich
ASKER CERTIFIED SOLUTION
Avatar of MichaelStaszewski
MichaelStaszewski
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rito1
rito1

ASKER

Thanks MichaelStaszewski,

That didn't seem to work in my C#... I am starting to understand there their a different implementation of regexp for different languages... this seemed to work fine:

\bAND\b|\bNOT\b|\bOR\b

Open in new window

SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm not a C# guy and use PCRE mostly. There are differences between regex engines. That's good you found a solution.
There's a nice comparison of features between the two (and others) on this page:  http://www.regular-expressions.info/refflavors.html