Team i have a text file of nearly 5 lakh records, each record with different syntax. InputExamples :
3~3~ALL Monthly~
3~4~Internal Ids~
9~4~FSVS ids~
9~3~Training Reports~
Need to Extract only rows that consists value=4 after 1st ~, and value=Ids after last ~
Output - 3~4~Internal Ids~ and 9~4~FSVS ids~
You can use the below regular expression to get the required output based on condition.
System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“(.*((?<=~)4).*)”)
Hope it helps!!
1 Like
Regex
1 Like
Hi,
Can you try the following sample?
strData.Split(vbcrlf.ToCharArray,StringSplitOptions.RemoveEmptyEntries).Where(Function(s) System.Text.RegularExpressions.Regex.IsMatch(s,"^[^~]*~4.*?Ids~[^~]*$",System.Text.RegularExpressions.RegexOptions.IgnoreCase)).ToArray()
Sample20230921-4L.zip (2.5 KB)
Regards,
1 Like
Hello @prerna.gupta
Try the regex matches method
YourString=“3~3~ALL Monthly~
3~4~Internal Ids~
9~4~FSVS ids~
9~3~Training Reports~
9~44~FSVS ids~
9~14~FSVS ids~
9~4~FSVS Jds~
125~4~Internal Ids~”
Use For each Loop
System.Text.RegularExpressions.Regex.Matches(YourString,".*(?<=~)4(?=~).*Ids~$|.*(?<=~)4(?=~).*ids~$")
Inside Loop Use CurrentItems.toString.Trim to get all matching values
1 Like
System.Text.RegularExpressions.Regex.Match(InputString,“.[4].”).Value
Hope It Helps!!
1 Like
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.