Regex Doubt1

Hi, I am new to this Forum and RPA as well, I need your help.
I have a text file which has a lot of data in it.
Eg:

deal :0
MT:876
Send:abc
Receive:xyz
Date:01 April 2022
Time:00:00:90
FT:A
Text:
MOR:7654
TRN
342
RR
0006
Narrative
ATTR:Grand
Letters of Advice

Like this I have data with different MT, send, receive, date, time etc.

Now I want to convert this text into an array, iterate it through a loop and scrape relevant data like MT, send, receive, date, time, the number which is below TRN, number below RR, and the word Grand from Narrative. Can anyone help me please. Thanks in advance.

I need to do in Regex

Hello @RpaUi02
First convert all in one line
newtex= yourText.Replace(Environment.NewLine, " ")
then use regex

Hi @RpaUi02 ,

Could you check the Expressions in the Screenshot :

For references on Regex :

Hi @Shubham_Kinge I am not familiar to Regex activity can you please explain me a bit more.

Hi @RpaUi02, welcome to the Community.

You can use the following RegEx pattern to extract the desired data in a collection:

MT:(\d+)\s+Send:([^\s]+)\s+Receive:([^\s]+)\s+Date:(\d{2}\s+\w+\s+\d{4})\s+Time:(\d{2}:\d{2}:\d{2})

The result will look like this:

In UiPath, you can use this expression to utilise the RegEx pattern capability:

resultCollection = System.Text.RegularExpressions.Regex.Matches(inputString, "MT:(\d+)\s+Send:([^\s]+)\s+Receive:([^\s]+)\s+Date:(\d{2}\s+\w+\s+\d{4})\s+Time:(\d{2}:\d{2}:\d{2})”)

Hope this

Hi @supermanPunch thank you for helping me out, I have tried in this way but I am able to generate MT, Send and Receive I am not able to generate Date, Time, TRN, RR and Narrative. Can you please help me.

Hi @arjunshenoy thank you for helping me I want TRN,RR and narative also, how to get those values

Hi,

Hope the following sample helps you.

Sample20230510-2.zip (2.7 KB)

Regards,

Hi @Yoichi thank you for helping me, I am getting error Option Strict On prohibits operands of type Object for operator ‘+’ while writing in write line

HI,

Can you share screenshot of the error?

Regards,

Hi,

If you use “item” variable from For Each activity, can you try to set String at TypeArgument in ForEach activity?

Regards,

Got it, But not able to get date and time getting error.

HI,

\ (back slash) is a special character of regex. If you need to use \ as normal character, please express it like \\

Regards,

Hi, Sorry for troubling you but I did not get you, do you mean that I should use this expression like “Send\Receive Date \s*:-\S*”

Can you try the following?

"Send\\Receive Date \s*:-\S*"

or simply replace it with dot.

"Send.Receive Date \s*:-\S*"

Regards,

Thanks a lot I got it. One last doubt now I want to add all this data to an excel can you please help me with that also.

hi @Shubham_Kinge how to use regex please help me

HI,

There are some ways to achieve it. For example, as the following.

Sample20230510-2v2.zip (3.3 KB)

Regards,