Need to get required data with Regex

Need to get data in between Highlighted roundup in below screenshot with Regex

can any one help

Thanks
shaik

one thing you can do , you can use the regex as key value pair , eg. in your case first search “Routing this section is applicable …” and then find the poistion of the text and then search the second text “Does number…” by this you can find in that these text are in the string then you can get the length of the string and then you can get the text in b/w these two patterns by using substring. another way is use Regex replace , replace both the strings “Routing " and “Does” with Space and the remaining text is your desired text.(first copy the whole text in a another string variable eg. strTemp and perform Regex replace on the temp one”

@shaik.muktharvalli1

Regular expression to capture first two lines and the last line

pattern = r’^.\n.\n|.*$’

try this

you can use this System.Text.RegularExpressions.Regex.Replace(yourTextInWhichYouReplace,patternToFind,ReplaceWith)
strString = yourWholeString;
String strTemp=strString;
string pattern_1= @“Routing This section is applicable …”
string pattern_2= @“Does Number…”
eg. strTemp=System.Text.RegularExpressions.Regex.Replace(strTemp,pattern_1,String.Empty);
strTemp=System.Text.RegularExpressions.Regex.Replace(strTemp,pattern_2,String.Empty);
Now the strTemp is the Remianing text

@rkelchuri
not matched any text

can you send sample workflow screenshot

thanks
shaik

The regular expression to capture the first two lines and the last line is:

^(.*\n.*\n).*?(\n.*)$

Explanation:

  1. ^(.*\n.*\n)
  • Captures the first two lines.
  • ^ matches the start of the string.
  • .*\n matches any characters until the first newline, repeated for two lines.
  1. .*?
  • Lazily matches everything in the middle of the text, ensuring it doesn’t consume the last line.
  1. (\n.*)$
  • Captures the last line, starting from the final newline.
  • $ ensures it matches until the end of the string.

Use this pattern in your desired tool or environment.

@rkelchuri

but need to get from below data

thanks
shaik

copy paste the text. Not screenshot.

Hi,

How about the following pattern?

(?<=4 Routing\s+.*\n)[\s\S]+?(?=Does Number Portability Apply)

Regards,

@rkelchuri

please take this text file

https://forum.uipath.com/uploads/short-url/f94JGHBBBo0q71vrGITiDHf37s2.txt

thanks
shaik

@Yoichi can you add "This section is applicable for " also in regex

thanks
shaik

Hi,

Can you try the following?

(?<=\n4 Routing\s+This section is applicable for.*\n)[\s\S]+?(?=Does Number Portability Apply)

Regards,

@Yoichi let me try, will confirm

thanks
shaik

This can help you get the text you need using regex.

(?<=This section is applicable for FRAFI)([\S\s]*)(?=Does Number Portability Apply?)

@Yoichi

I need to get before two lines and last one line also

Before two lines :
4 Routing
This section is applicable for

Last line:
Does Number Portability also

Please help

thanks
shaik

Hi,

How about the following?

(?<=^|\n)4 Routing\s+This section is applicable for[\s\S]+?Does Number Portability Apply.*

Regards,

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