thao.dinh
(Thao Dinh)
June 14, 2024, 9:42pm
1
I have a string variable OutputValue which contents some ". I want to use RegEx to get content of refreshToken but the pattern portion does not accept ". When I tried to change " " in the pattern portion hoping with would recognize ", it does not work either.
refreshToken = System.Text.RegularExpressions.Regex.Match(OutputValue,“.refreshToken":\s"(\w+). ”).ToString()
Sample of OutputValue
Status: 200Connection: nginx{ “refreshToken”: “AB11727rerfd”, “accessToken”: “12342dfdgfg”}
Desired Result
refreshToken = AB11727rerfd
ppr
(Peter Preuss)
June 14, 2024, 10:03pm
2
Regex Approach
(?<=refreshToken"": "")[\s\S]+?(?="")
looks like your input is partly a JSON and maybe a hybrid approach would also be a good strategy
Anil_G
(Anil Gorthi)
June 15, 2024, 2:56am
3
@thao.dinh
It is a json response…you can actually use deserialize json and from the output use jobj("refreshToken").ToString
Cheers
Hi
You need to escape the quote character with a backslash.
Like this:
\"
Updated pattern:
(?<=refreshToken\“: +\”)[\s\S]+?(?=\")
Or you can use a different regex character for the quote marks like this:
(?<=refreshToken\S: +\S)[\s\S]+(?=\S,)
Cheers
Steve
vrdabberu
(Varunraj Dabberu)
June 16, 2024, 3:03pm
5
Hi @thao.dinh
Please check the below flow:
Input = Status: 200Connection: nginx{ "refreshToken": "AB11727rerfd", "accessToken": "12342dfdgfg"}
Output = System.Text.RegularExpressions.Regex.Match(Input,"(?<={)(.*)(?=,)").Value.Trim()
RequiredData = Output.Replace("""", "").Replace(",", "").Replace(":", "=")
Regards
thao.dinh
(Thao Dinh)
June 17, 2024, 9:18pm
6
thanks! This works perfectly. Somehow UiPath does not recognize " so changing to “” works.
ppr
(Peter Preuss)
June 17, 2024, 9:19pm
7
when using a " within a string we have to escape with another one. This was applied
thao.dinh
(Thao Dinh)
June 17, 2024, 9:20pm
8
Looks like " does not work on UiPath so changing to “” from your suggestion works. Thanks
system
(system)
Closed
June 20, 2024, 9:21pm
9
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.