RpaUi02
(RPA UIpath02)
May 9, 2023, 3:08pm
1
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.
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 :
This CheatSheet introduces the basic use of regex functions. With further examples also special cases are presented.
Introduction
From the namespace System.Text.RegularExpressions following methods are offered:
Regex.Match
Regex.Matches
Regex.isMatch
Regex.Replace
Regex.Split
A simple usage for example would look like this:
[grafik]
Recommendation:
add System.Text.RegularExpressions to the imports:
[grafik]
it allows to use the shortened statement, as the namespace part can be ommited…
RpaUi02
(RPA UIpath02)
May 9, 2023, 3:23pm
5
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
RpaUi02
(RPA UIpath02)
May 9, 2023, 7:14pm
7
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.
RpaUi02
(RPA UIpath02)
May 10, 2023, 1:48am
8
Hi @arjunshenoy thank you for helping me I want TRN,RR and narative also, how to get those values
Yoichi
(Yoichi)
May 10, 2023, 2:11am
9
Hi,
Hope the following sample helps you.
Sample20230510-2.zip (2.7 KB)
Regards,
RpaUi02
(RPA UIpath02)
May 10, 2023, 2:53am
10
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
Yoichi
(Yoichi)
May 10, 2023, 2:55am
11
HI,
Can you share screenshot of the error?
Regards,
Yoichi
(Yoichi)
May 10, 2023, 3:07am
13
Hi,
If you use “item” variable from For Each activity, can you try to set String at TypeArgument in ForEach activity?
Regards,
RpaUi02
(RPA UIpath02)
May 10, 2023, 3:20am
14
Got it, But not able to get date and time getting error.
Yoichi
(Yoichi)
May 10, 2023, 3:25am
15
HI,
\
(back slash) is a special character of regex. If you need to use \
as normal character, please express it like \\
Regards,
RpaUi02
(RPA UIpath02)
May 10, 2023, 3:32am
17
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*”
Yoichi
(Yoichi)
May 10, 2023, 3:34am
18
Can you try the following?
"Send\\Receive Date \s*:-\S*"
or simply replace it with dot.
"Send.Receive Date \s*:-\S*"
Regards,
RpaUi02
(RPA UIpath02)
May 10, 2023, 3:42am
19
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
Yoichi
(Yoichi)
May 10, 2023, 5:15am
21
HI,
There are some ways to achieve it. For example, as the following.
Sample20230510-2v2.zip (3.3 KB)
Regards,