Is there a Regular Expression that would give me a name value pair from the string below that would look like this:
statuscode = 179640000
new_Approved = 179640002
from:
&$filter=statuscode/Value eq 179640000 and new_Approved/Value eq 179640000
Is there a Regular Expression that would give me a name value pair from the string below that would look like this:
statuscode = 179640000
new_Approved = 179640002
from:
&$filter=statuscode/Value eq 179640000 and new_Approved/Value eq 179640000
the sample program:
public static void Main()
{
string src = "&$filter=statuscode/Value eq 179640000 and new_Approved/Value eq 179640000";
Regex regex = new Regex(@"(\w*)/Value eq (\w*)");
foreach (Match m in regex.Matches(src))
{
foreach (Group g in m.Groups)
{
Console.WriteLine(g.Value);
}
}
}
gives the following output
statuscode/Value eq 179640000
statuscode
179640000
new_Approved/Value eq 179640000
new_Approved
179640000
Press any key to continue . . .
What you have for each group in a match is:
It assumes that all names and values are only alphanumeric and '_'
, It also assumes that there are no other curveballs that your source string has.
^&filter=({[0-9a-zA-Z]+}/Value eq {[0-9a-zA-Z]+})( and )?)$
I think that would work as a general template. You'll need to modify the syntax a bit to work with whatever regex engine you're using.