0

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

Dai
  • 141,631
  • 28
  • 261
  • 374
GoBeavs
  • 499
  • 2
  • 10
  • 25
  • Look at [this Stackoverflow question](http://stackoverflow.com/questions/168171/regular-expression-for-parsing-name-value-pairs). Same thing, except instead of commas, your pairs are separated by `|` – Icemanind Sep 25 '12 at 20:54

2 Answers2

1

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:

  1. the match itself
  2. the name of the value
  3. the value itself.

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.

0

^&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.

Dai
  • 141,631
  • 28
  • 261
  • 374