Regex to get any 4 Digit or Character or Both, Inside a Double Qoute

I have this JSON Response with a series of Error Codes like this

ErrorList[
  {
    "CODE": "0021",
    "TITLE": "Error: Customer Number Invalid",
},
{
"CODE": "0A51",
    "TITLE": "Error: Currency Invalid",
},
{
"CODE": "043C",
    "TITLE": "Error: Payment is Unbalanced",
}

The number of error codes varies from every post request. I am trying to get the value under CODE. Is there a way to get it using regex? I tried using this /(?<=")\d+(?=")/g But it only gets the numbers, the codes I get are mixed with characters.

Hi

Hope this expression helps you resolve this

Use Matches activity and mention this expression

(?<=CODE\W\W\s\W).*(?=\W,)

This will get all the values of CODE of any type
Be it character or number

Cheers @Shinjid

2 Likes

Hi @Shinjid

You can try with below Regex

System.Text.RegularExpressions.Regex.Match(strinput.ToString,”(?<=")\d+\S+(?=")”).ToString

Regards
Gokul

1 Like

Hi,

Another solution:

mc = System.Text.RegularExpressions.Regex.Matches(yourString,"(?<=CODE\W+)\w+")

Note: mc is MatchCollection

Regards,

1 Like

Thank you very much! This worked for me.

1 Like

This also worked, Thank you.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.