Need help to read text files content and extract matched data value with regular expressions

Hi everyone,

I have a folder containing a number of text files that I want to read and iterate and capture matched specific data value using regular expressions. Each text file has its own set of data values to be captured.
I have tested the regular expressions at and am able to match the desired text value correctly. However, in the UiPath workflow sequence I am unable to get any match or output any of the desired data value from the text files. Below are the list of steps I took to building the workflow but I am not sure if I have missed out any steps or having any mistakes in the workflow activities.
Any assistance is greatly appreciated.

Here are the workflow sequence done so far:

  1. I add a Assign activity to get the text files path location. Folder is a string variable of the full path where the text files are located.

  2. Next, I add a For Each activity to loop each item in filesArray. In the Body of the For Each activity, I add Read Text File activity with Filename=item.ToString (as the path of the file to be read). The Output variable is textInput of string variable type.

  3. Next, I add a Assign activity to read the text file line by line with a System.String variable textStr=textInput.Split(Environment.NewLine.ToArray()).

  4. Next, I add a Matches activity to configure the regular expressions. Input variable=textStr.ToString and Result=regexMatch of variable type System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Match>.

Here is the regex:
(?<=SERVER: )\w+|(?<=SCSI Disk Device: )…|(?<=Gb.Gb.+Gb\s+)\d+.:

Here is a sample text and the value highlighted in bold are the data to be captured as input into Excel file:

SERVER: server001
SCSI Disk Device: OK
SCSI Disk Device: OK
SCSI Disk Device: OK
SCSI Disk Device: OK
Drive Size Used Free Free(%)
C: 499Gb 131Gb 368Gb 73.7
D: 99Gb 10Gb 89Gb 89
E: 1843Gb 800Gb 1043Gb 56.5
F: 1843Gb 647Gb 1195Gb 64.8


How about the following pattern?

(?<=SERVER:\s*|SCSI Disk Device:\s*|Gb.+Gb.+Gb\s*)[.\w]+



sorry for the confusion, but that is not what I meant. I do not need to configure any regular expression as I am able to get a match on
What I am trying to say is how do I build the UiPath activities to capture the desired data value from the text files. When I try to check if the matching value is correct, I get “System.Linq.Enumerable+d__94`1[System.Text.RegularExpressions.Match]”.

@michael.ho What operation are you performing to check the matching value ?


In this case, perhaps you don’t need to split the string.
You can set whole string in Input property of Matches activity, and can check its value as the following.



I add a Message Box activity with regexMatch.ToString to test the output. I got this output “System.Linq.Enumerable+d_97’1[System.Text.RegularExpressions.Match]”.

Thank you for your help. I found the solution at this post Regex output in Matches box

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