RegEx does not recognize double quotation

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

Regex Approach

(?<=refreshToken"": "")[\s\S]+?(?="")

looks like your input is partly a JSON and maybe a hybrid approach would also be a good strategy

@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

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

thanks! This works perfectly. Somehow UiPath does not recognize " so changing to “” works.

when using a " within a string we have to escape with another one. This was applied

Looks like " does not work on UiPath so changing to “” from your suggestion works. Thanks

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