How to get text data

Hi, I have a text in notepad and need to convert that data into an array and need to scrape Relevant data using Regex. Please help me.

The text file Contains data like below

Identifier-0
Type-456
Sender-ABCD
Receiver-xyz
Date-2-February-2023
Time - 00:00:19
File Type - A
TRNumber - 12345
RR - 098765
Narrative
GST: GUARANTEE

From the above text i need Type, Sender, Receiver, Date, Time, TRNumber, RR and GST.

Please help me, Thanks in advance

Hi @Sujitha_A, welcome to the Community.

You can use the following RegEx patterns to extract the data from the given input:

Type-(.*)

Sender-(.*)

Receiver-(.*)

Date-(.*)

Time - (.*)

TRNumber - (.*)

RR - (.*)

Narrative[\s\S]*GST: (.*)

Output:

image

image

image

In UiPath, You can use the following syntax:

typeData = System.Text.RegularExpressions.Regex.Match(yourInputData.ToString,"Type-(.*)").Value

senderData = System.Text.RegularExpressions.Regex.Match(yourInputData.ToString,"Sender-(.*)").Value

Hope this helps,
Best Regards.

@Sujitha_A - Hi Sujitha, as @arjunshenoy mentioned you can use Read Activity followed by split operation to convert text into array and then performing Regex operations. I am also attaching my solution in steps:

  1. Read the text file using the “Read Text File” activity in UiPath and store the output in a variable, let’s say “textData”.
  2. Split the “textData” variable using the “Split” function with delimiter as “newline” to convert the text data into an array. Store the output in a variable, let’s say “dataArray”.dataArray = textData.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
  3. Use the “Matches” activity in UiPath to scrape relevant data using regular expressions.For example, to extract the Type, Sender, Receiver, Date, Time, TRNumber, RR, and GST values from the “dataArray” array, you can use the following regular expressions:
    typeRegex = “(?<=Type-)\d+”
    senderRegex = “(?<=Sender-)[A-Za-z]+”
    receiverRegex = “(?<=Receiver-)[A-Za-z]+”
    dateRegex = “(?<=Date-)\d{1,2}-[A-Za-z]±\d{4}”
    timeRegex = “(?<=Time - )\d{2}:\d{2}:\d{2}”
    trNumberRegex = “(?<=TRNumber - )\d+”
    rrRegex = “(?<=RR - )\d+”
    gstRegex = “(?<=Narrative\s*).*”
  4. Loop through the “dataArray” array using the “For Each” activity in UiPath.
  5. Inside the loop, use the “Matches” activity with the respective regular expressions to extract the relevant data and store it in variables.
  6. Store the extracted data in a data table or any other data structure as per your requirement.

Cheers!!!

Hi @Sujitha_A ,

Welcome to the UiPath Community!

Go to matches activity
Type the following for all the fields that you want:

Or if this looks like the long way use assign activity and inside there you can use the following
Regex.Match(text,“Type-(.)”).Value.Trim
Regex.Match(text,“Sender-(.
)”).Value.Trim
Regex.Match(text,“Receiver-(.)”).Value.Trim
Regex.Match(text,“Date-(.
)”).Value.Trim
Regex.Match(text,“Time - (.)”).Value.Trim
Regex.Match(text,“TRNumber - (.
)”).Value.Trim
Regex.Match(text,“RR - (.)”).Value.Trim
Regex.Match(text,“GST:(.
)”).Value.Trim

Regards,
Aditya

Hi @shantanu_chande thank you for your quick response, can you please help me with the 5th point which you have mentioned

Thank you all

@Sujitha_A If you are good with the resolution, can you mark this ticket as solved if possible.

@Sujitha_A You need to loop the extracted array from point 2 and then inside that you should use matches activity along with the regex to extract required value. Also please make sure, these regex identifier should be kept in Config file so that you can alter them in future without making code changes.

HI @shantanu_chande Can you please help me in doing this in a xaml and share me if you dont mind

@honey.123.631 I have added the flow in the personal thread your tagged me in.