How to access first index of result from activity the Matches and store as string?

I’m using UiPath StudioX version 2021.10.4, and using the “Matches” activity to search a text file generated from Read PDF with OCR. I should only need to access the first index of result, but am having trouble doing that. The result won’t show up in the “save for later” activity. It does work with the “for each” activity, but I’m unsure how to save the first result to a variable for later use. I have been able to store the results in a text file, but unsure of how to get info from that text file without using the “Matches” activity (starting this whole process over).

For example, the result from Matches would be named ‘MatchingDatesResult’

EDIT: Thanks everyone for trying to assist with this. It looks like the activity I’m using got updated and has the exact functionality that I was missing that caused the original issue. This issue is fixed now.

Hi @chris5

You can try Find Matching Patterns Activity instead. The result will be a string variable for the first match. If the text is not found the result will be an empty string

Cheers

The only other activites I can use are “Is Match” and “Replace” unfortunately. I can download another package if that’s what I need.

Hi @chris5

Try using the below syntax

Output = System.Text.RegularExpressions.Regex.Matches(Inputvariable.ToString,"RegexPattern")

The output variable stores all the matches and use the for each activity and pass the output variable into the for each activity so that you can loop through each data extracted.

Regards

Hi @chris5

I get it.

You can use

MatchingDatesResult(0).value or MatchingDatesResult(0).ToString to access first ocurrence in Advanced Editor.

If it doesn’t work, please share the regex pattern and settings you are using

Cheers

This is the pattern I’m using \b(\d{2}[/\-.]){2}\d{2,4}\b

I also uploaded what the properties section looks like for this activity.

When trying what you sent previously, I get this same error for both options,
“‘MatchingDatesResult’ is not declared. It may be inaccessible due to its protection level.” Can provide more info on my settings.


Error showcase

Hi @chris5

Try this

in Result property field in match activity, click in + button → Clean Value

Then click again in + button → Create Variable → Give it a name

Try again using this new variable

Make sure the variables are in the same scope that you trying to use them

Would that info go into the result section for the Matches activity? I’ve only been able to declare variables using the Save For Later activity, and I wasn’t able to use the provided info there. I can describe it more or post images to clear up any confusion.

I tried this but no luck unfortunately. I can provide a screenshot of any specific settings if needed.

@chris5

is it possible to you share the project with dummy data ?

Hi @chris5

Try to use this in Value to Save field in Save For Later Activity in Advanced Editor

Saved.Values(Of System.Collections.Generic.IEnumerable(Of System.Text.RegularExpressions.Match))("MatchingDatesResult")(0).Value

This is what comes up when I set that value. You can see those comparison symbols show up and the full phrase is MatchingDatesResult > 0 > value.

Here is the advanced editor to show I put the same value in. I posted another image before showing more info as well.

The properties for the Matches activity was changed to include this First Match option, which solves the issue I was having.
image

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