Extract the specific Text from the Text file

Hi team, I am facing an issue,

I am having the Text file and contains the text as shown below

D1234 First Value $0.00

D5678 second - Value$5.00

D2356 Third value $0.00

D78967 Fourth Value$0.00

D3678 Fifth value $0.00

Soon…

Here i would like to extract the Value which is starting with D follwed by 4 numeric values(EX: D1234) and their corresponding text(First Value $0.00) in another value.

I would like to loop and have to extract.

I am able to get the first value but while loo[ing I am facing the issue.

Can any one help me on this.

Thanks
Sreenivas

Please use below regular expression in matches activity and loop through the results using for each activity
D(\d{4})(.*)

Regards,
MRMK

Please mark as solution if found helpful

Hi,

Hope the following helps you.

mc = System.Text.RegularExpressions.Regex.Matches(yourString,"(^D\d+).*?(\$[.\d]+)\s*$",System.Text.RegularExpressions.RegexOptions.Multiline)

Sample20220621-3.zip (2.5 KB)

Regards,

Thanks for the reply Yoichi,

I want the Total text( First Value) but I am getting only $0.00 value

Thanks
Sreenivas

Hey @srinusoft37

We can achieve this using Regex Groups :blush:

Using Regex groups will allow you to collect both elements with one pattern. Take a look here to preview the pattern. Like this:
image

image

High Level steps to achieve this:
Step 1: Use a Matches activity to collect your results
Step 2: Insert a For Each
Step 3: Refer to each as group like this: “item.Groups(1).ToString”
“1” equates to the corresponding group from the highlighted image above.
Step 4: Assign each group to a result/save in a dataTable etc

I have made a demo workflow you can use.
Main.xaml (8.1 KB)

Hopefully this helps :blush:

Cheers

Steve

Thanks @Steven_McKeering

Here i am getting the second string as $ value, but I nee the whole test after D value like(First value) $0.00 is not required

Thanks
Sreenivasa

Hey @srinusoft37

The regex pattern is matching the whole line yes, but only processing values in Red which are in ‘groups’. The Orange text is just for reference.

We are only using the ‘Groups’.

Does that make sense. Take a look at this Regex101 sample
The Blue text results will be ignored.
image

Cheers

Steve

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