Regex inquiry on UIPath

Hello everyone,

I would like to ask for help on how to use Regex correctly. I am trying to extract access token on a txt file.
This is what I am trying to extract
image

I am using this syntax “System.Text.RegularExpressions.Regex.Match(result.TextContent, “(?<=access_token[””:\s]*)[A-Za-z0-9-_]+“).Value” but its only extracting the first 4 digits (1000).

any advice on what the correct syntax is?

Hello @mapaje Try this regex

System.Text.RegularExpressions.Regex.Match(result.TextContent, “(?<=access_token"\s*:\s*“)[^”]+”).Value

Cheers

Hi, @mapaje

use the following regex pattern:

System.Text.RegularExpressions.Regex.Match(
result.TextContent,
““access_token”\s*:\s*”([^“]+)”"
).Groups[1].Value

@bhavesh.choubey and @arjun.shiroya,

Thank you for the help, I have tried both and they have given me what I wanted to extract.

Hey @mapaje you’ve to mark the correct answer as solution not yourself as a solution. If you want to be marked as solution then give the answers to the topics not just raise the topic and mark yourself as solution.

Cheers

@bhavesh.choubey,

Thank you for the advise, I will be doing that then.

1 Like

Hi

Your original regex pattern looks to be failing because you didn’t consider the “.” values in the token.

You just needed to update the square brackets with a “\.” The backslash is to escape the “.” in regex. You need to escape that character within the square brackets because “.” means any character.

Cheers

1 Like

Hello @Steven_McKeering

Thank you for this, I am new to coding so this is very helpful as I am currently learning syntaxes.

1 Like

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