标签云

微信群

扫码加入我们

WeChat QR Code

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)/ibut this only returns [0] = ([IsActive]=(1)) AND[1] = ANDSo 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


This is giving me a syntax error pointing to (?i)

2019年04月22日13分50秒

WillP., It is ignore-case option. Try use /i instead.

2019年04月22日13分50秒

I am only getting the first one returning using cyber-reality.com/regexy.html

2019年04月22日13分50秒

WillP., Try this JavaScript tester: regexpal.com. It gives correct result.

2019年04月22日13分50秒

thanks got it working

2019年04月22日13分50秒