You could use a regex that looks something like this:
([a-zA-Z]\w*)\s*(<|>|(={1,2})|!=)\s*([a-zA-Z]\w*)
That will match three things:
- a word consisting of an upper or lower case character followed by any number of upper or lower case characters or digits
- one of "=", "==", "<" or ">" for comparison
- a word with the same definition as #1.
After that, all you need to do is get the matches and groups, look at the two words and look at the comparison type and go from there.
Here's some sample code that uses this:
private void RegexTest()
{
var regex = new Regex(@"([a-zA-Z]\w*)\s*(<|>|(={1,2})|!=)\s*([a-zA-Z]\w*)");
var inputs = new string[]
{
"XYZ = XYZ",
"ABC != A",
"1 > 3",
"a12 < m34"
};
foreach (var input in inputs)
{
var match = regex.Match(input);
if (match.Length > 0)
{
Debug.WriteLine($"Match for ({input}): First: {match.Groups[1]}, Comparer: {match.Groups[2]}, Second: {match.Groups[4]}");
}
else
{
Debug.WriteLine($"No match for {input}");
}
}
}
This results in output that looks like:
Match for (XYZ = XYZ): First: XYZ, Comparer: =, Second: XYZ
Match for (ABC != A): First: ABC, Comparer: !=, Second: A
No match for 1 > 3
Match for (a12 < m34): First: a12, Comparer: <, Second: m34