Let me start by saying that I'm not the greatest with Regular Expressions, but from research it seems that they are the best way to go for what I need; I just don't fully understand how to use them with matching groups.
In my application I need to parse a boolean string that can have any number of parameters. The following are some examples:
I need to be parse any variation of these strings ('and' and 'or' are the only boolean operators that can be present) so that I get a list such as:
I don't need to parse the strings with the '=' sign, but I do need the 'or' & 'and' operators so when I build my query in code I know how to connect each statement to the next (ie:Name=John should be ORed with Name=Jane which should be ANDed with Date=Now) So far I have only been able to get a list such as
by using the following code:
but I lose the boolean operators in the process. If anyone could please help me with a regular expression so I would get the groups I have now, but with the operators in between the appropriate expressions, it would be greatly appreciated.
Thanks.
In my application I need to parse a boolean string that can have any number of parameters. The following are some examples:
Name=John or Name=Jane Name=John or Name=Jane and Date=Now
I need to be parse any variation of these strings ('and' and 'or' are the only boolean operators that can be present) so that I get a list such as:
Name=John or Name=Jane and Date=Now
I don't need to parse the strings with the '=' sign, but I do need the 'or' & 'and' operators so when I build my query in code I know how to connect each statement to the next (ie:Name=John should be ORed with Name=Jane which should be ANDed with Date=Now) So far I have only been able to get a list such as
Name=John Name=Jane Date=Now
by using the following code:
Dim Pattern AsString = "(\S+\x3D\S+)"While Regex.Matches(query, Pattern).Count > 0Dim oMatches As MatchCollection = Regex.Matches(query, Pattern)ForEach oMatch In oMatchesDim Operand1 = oMatch.Groups(0).ValueNextEndWhile
but I lose the boolean operators in the process. If anyone could please help me with a regular expression so I would get the groups I have now, but with the operators in between the appropriate expressions, it would be greatly appreciated.
Thanks.