I'm trying to parse apart the different filter strings for an sql server WHERE clause, and I thought that regular expressions would be the way to go. Fortunately, the filter will always be flat, there will be no "sub-filters". Each filter statement will always be surrounded in parenthesis. Here's an example of a string I'd like to parse:
([IsActive]=(1)) AND ([NoticeDate] >= GETDATE()) AND (NoticeDate <= DATEADD(day, 90, GETDATE()))
The result I'd like is an array with the following items:
[0] = ([IsActive]=(1)) AND
[1] = ([NoticeDate] >= GETDATE()) AND
[2] = (NoticeDate <= DATEADD(day, 90, GETDATE()))
The closest I've come is the following regex:
/\(.+?\) (and|or)/i
but this only returns
[0] = ([IsActive]=(1)) AND
[1] = AND
So basically I'd like to return anything surrounded in parenthesis, followed by a space, followed by the string "and" or "or". The last statement will not be followed by and/or, though I could concatenate a " and" string if that would make it easier. This is being done using classic asp JScript. I've pretty much exhausted my (weak) regular expression abilities, any help would be greatly appreciated. Thanks in advance
