RegEx Match Activity

Hi all,

I wish to extract certain string based on fixed pattern of the input String I am providing and for this I am using Matches activity of Uipath. The problem I am facing is while extracting data from multiple lines. My Input String looks like below:

28 - Country - Germany (DE)
83 - Location - F 709, Ludwigshafen, Germany
448 - Building - F 709
449 - Floor - EG
450 - Room - 3
461 - Remark / Comment - Example Text
519 - Number of LAN ports -
723 - Wall outlet number - Example Number
1046 - Patch removal -
1047 - GSP Message ID - Port_Patching
1122 - Aftercare - Aftercare

Expression before “-” is the fixed pattern for all lines, like in "448 - Building - " left site expression is fixed. If I wish to extract only one line, Matches is working fine with Pattern “448 - Building - (.*)” but if I want to extract data from more lines, it fails. :expressionless:

can anyone suggest how can I use multiple patterns to extract multiple expressions.


from this what is the term from each line you are expecting it as output
can you give us an example
Cheers @mayank_26

The output can be arrary/string of below from the same example I have stated above.

Germany (DE)
F 709, Ludwigshafen, Germany
F 709
Example Text

Example Number


1 Like

keep this whole string in a text file
–now use read text file activity and get the output with a variable of type string named str_input
–now use a assign activity like this
arr_strings = str_input.Split(Environment.Newline.ToArray())
where arr_strings is a variable of type array of string
–now use a FOR EACH ACTIVITY and pass the above variable arr_Strings as iinput and change the type argument as string in the property panel
–inside the loop use WRITELINE activity with this expression

Cheers @mayank_26

That’s because your regex is not dynamic enough. If you want the “Matches” activity to return all those items, make your regex more dynamic.

Try this:

“(\d+)( +)-( +)([\w\s/\]+) -( *)(.<*asterisk>)”

EDIT: There’s some problem here. Don’t include the word “asterisk” in your regex. DO include the wild card, though.


I used similar Regex “\d+\s-\s(?:.* - )(.*)” and it is working fine. I think it will work in match, I will test this, can you suggest how Output of Match seems like ?


You can get it using Matches activity with the following settings.

Pattern : "(?<=^\d*?\s*-.*?-\s*).*$"
Check Mulitline of Regex Option property.


1 Like

Mention this in MATCHES activity and get the output with a variable named out_matches and enable multilingual option as @Yoichi suggested
—now use a FOR EACH activity and pass the above variable as input and change the type argument as System.Text.RegularExpressions.Regex.Match in the property panel of for each loop
—inside the loop use a writeline activity and mention like this

Cheers @mayank_26

It will work fine except for line items like the one here: “519 - Number of LAN ports -”
Add another * after the last space character.

true, it is working for some expressions but not for all, I think I need to explore more patterns to get exact match for complete string, though multiline option helped. :slight_smile:

1 Like

I tried and my pattern is capturing right elements, now I wish to extract them but for each activity is not showing the correct output.

I tested with this data and it shows matches. (in yellow)

How can I extract this information line by line in String ?

I’d suggest Regex using Matches.

Specifically, you could use something like this if you’re sure that the input is going to always be in that format where there’s a number, hyphen, thing, hyphen, thing you want captured:

1 Like

Hi @dmccammond,

I am using the same thing, but its the position i think not able to understand. Could you suggest if this is the community edition you are using in the screenshot ?

If yes the version ?

When dealing with regular expressions, you should use a tester first to make sure that the Regex applies to your data. In the example I posted, I used .NET Regex Tester - Regex Storm, which is advisable as it uses the .NET language Regex.

I did use the tester and it shows that it is separating the expression using this pattern. Problem I am facing it to extract this information.

Like myVariable(3).ToString is showing me 449 - Floor - EG since it is in Index 3. but I need EG only out of this.

BTW, this is system based information and will be in same format always.

I found the error with the help of .NET Regex Tester - Regex Storm.

The Pattern which we were using was incorrect thus it was not showing the correct value. This this Regex Tester I could finally locate the position and extract the elements.

For my String, the actual pattern was (?!.-)(.).

Thanks Everyone for their help . :slight_smile:

1 Like