Shinjid
September 22, 2021, 7:54am
1
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
Gokul001
(Gokul Balaji)
September 22, 2021, 8:08am
3
Hi @Shinjid
You can try with below Regex
System.Text.RegularExpressions.Regex.Match(strinput.ToString,”(?<=")\d+\S+(?=")”).ToString
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.
Regards
Gokul
1 Like
Yoichi
(Yoichi)
September 22, 2021, 8:17am
4
Hi,
Another solution:
mc = System.Text.RegularExpressions.Regex.Matches(yourString,"(?<=CODE\W+)\w+")
Note: mc is MatchCollection
Regards,
1 Like
Shinjid
September 22, 2021, 8:25am
5
Yoichi:
(?<=CODE\W+)\w+
Thank you very much! This worked for me.
1 Like
Shinjid
September 22, 2021, 8:25am
6
This also worked, Thank you.
system
(system)
Closed
September 25, 2021, 8:26am
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.