RegEx for Text File

Hey All,
I am using a txt file with 5 lakh records where in i need to extract desired string from each row.
have stored text file in Match Collection and using for each row to iterate as below :
image

Input Eg : 1168~abcd~null~3~1~0~2009-10-27 05:00:00~2009-10-27 05:00:00~2021-06-16 10:13:35~2009-10-27 05:00:00~2009-10-28 01:13:34~

Desired Output : Need to extract 1st value before ~ and storing in str_SerialNo variable=1168

@prerna.gupta

are you facing any issue with it?

Can you please elaborate the issue

You can use item.Value.Split("~"c).First

Assuming matchcollection is a collection of match and not strings

Can you please let us know what is there is match collection if this does not work

Cheers

Hi @prerna.gupta

You can use the below regular expressions.

System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“(^\d+(?=~))”)

Hope it helps!!

@prerna.gupta

The expression u r using is already correct
May I know what issue u r facing
@prerna.gupta

This is similar to item.ToString.Split("~"c)(0) and it extract only 1st numeric digit before ~ ie 8 instead of 1168
For each - list of match collection only

HI @prerna.gupta

str_SerialNo=strinput.Split({“~”},StringSplitOptions.RemoveEmptyEntries)(0)

strinput = “1168~abcd~null~3~1~0~2009-10-27 05:00:00~2009-10-27 05:00:00~2021-06-16 10:13:35~2009-10-27 05:00:00~2009-10-28 01:13:34~”

you can try this

item is of match collection type.
Suggested is throwing error MatchCollection cannot be converted to String

Okay @prerna.gupta Use the below one

System.Text.RegularExpressions.Regex.Match(yourstringinput.ToString,“(^\d+(?=~))”).Value

Hope you understand!!

you can change the variable type to matchcollection

then it will work

@prerna.gupta

@prerna.gupta

Can you please use a log message and show what is there is each item…please log the item…looks like the matchcollection itslef is missing 116 in it

Cheers

I need to extract multiple values from Input String due to which not using RemoveEmptyEntreis function

To be precise i need to extract 2 values
Value 1 = Anything before 1st ~ symbol = 1168
Value 2 = Anything after 1st ~ symbol = abcd (this is working good using item.ToString.Split("~"c)(1))

Issue Facing - Getting only 1st numeric digit before ~
Output = 8
Desired Output = 1168

HI @prerna.gupta
1.Value 1 = Anything before 1st ~ symbol = 1168

System.Text.RegularExpressions.Regex.Split(strinput,“~”)(0)

2.Value 2 = Anything after 1st ~ symbol = abcd
System.Text.RegularExpressions.Regex.Split(strinput,“~”)(1)

let me know its working or not for you

Multiple Errors

image

I’m sharing the xaml you can follow same as it is

Xaml : - RegEx for Text File.zip (1.9 KB)

@prerna.gupta

Sure let me try. Thanks

if not you can try this screenshots

you can see the out

image
@prerna.gupta


Dependencies errors

can you share the screenshots of your flow
@prerna.gupta