Regex patten

I Have figured out regex pattern - but not sure how to use it in UiPath
Please help me with the package if any need to be installed - would be great if i had some sample workflow

Note : I need to get the values which has marked in blue

Hi,

Create a variable with your regex pattern as

 regexObj As New Regex("([0-9]+) replace this with your pattern ([0-9]+)", RegexOptions.IgnoreCase)

Then inside an assign use this

regexObj.Match(yourString).Groups(1).Value
1 Like

Thanks for immediate response @sarathi125 . am getting error as in image.
should i need to close them in double Quotes.

Do it in the variable section as shown below,

@sarathi125 – Thanks for your time.

Have uploaded my workflow - can you please verify it because am not getting any output.regex.xaml (5.9 KB)

Below are things am trying to perform

  1. Read one txt file and storing it on one variable
  2. using assign activity getting the values matches
  3. Displaying it using write line.

not able to upload my text file here - excuse me

Hi
lets take you have the input stored in a variable name str_input
so in the assign activity mention like this
out_matches = System.Text.RegularExpressions.Regex.Matches(sr_input,“your regex expression”)

where out_matches is a variable of type
System.Collections.Generic.Ienumerable(system.text.RegularExpressions.Regex.Match)

then we can pass this out_matches variable as input to a FOR EACH activity and inside that loop use a writeline activity and mention like item.ToString which will print all the values one by one

Cheers @Fresher

Hi

I attached the Workflow with Same input file which attached in the Question

Important Points to remember :
1.In Matches Activity Property Panel: Ensure the RegexOption= Multiline is selected
image

2.In For Each Activity property Panel:Change TypeArgument to system.text.RegularExpressions.Match

PFA,
testing.zip (13.4 KB)

Hi @Fresher,

Please go to Package Manager first. Then go to All Packages and type System.Regex. After finding it Install it.

Now go to Design pane and find Imports and type System.Regex. Now Double Click on it. Now you are all set.

If found any issue close the .xmal file or the close the Studio. Now Reopen it.

Hope you will be able to use Regex in your workflow.

Thanks & Regards,
Apurba

Hi @VISHNU07.

Thanks for the workflow file - but regex pattern which you have used will not suit all the criteria. I need to use below pattern.

Blockquote (?<=Table STH-1\nNATIONAL STUDENT HOUSING MARKET)(.\n)+(.)(?=NATIONAL STUDENT HOUSING MARKET – SELECT SURVEY RESPONSES*)

can you please try with this - i tried with this but still not able to generate the output, however in test regex builder the data are getting captured.not sure where am missing.

Thanks for the package details :slight_smile: @apurba2samanta

Most welcome @Fresher :slightly_smiling_face:

Thanks & Regards,
Apurba

Hello @Palaniyappan

Thanks for your time - i don’t find System.Collections.Generic.Ienumerable(system.text.RegularExpressions.Regex.Match) variable type - can you please confirm on it

I found below variable type is used for getting the output of ‘Matches’ :
System.Collections.Generic.IEnumerable<System.Text.RegularExpressions.Match>

Please assist - Thanks

Sure send the input text file
I will check and update

@VISHNU07

Please consider the same input text file.

Starting condition should be a combination of below :
Table STH-1
NATIONAL STUDENT HOUSING MARKET

Ending condition should be as below
NATIONAL STUDENT HOUSING MARKET – SELECT SURVEY RESPONSES*

eg:

xys
sdfgasg
sdasggasga asdfsd asgfas
Table STH-1
NATIONAL STUDENT HOUSING MARKET






… … …
NATIONAL STUDENT HOUSING MARKET – SELECT SURVEY RESPONSES*
fasdfasd
asdfasdfasdf

Note: I need the data present between the bold lines.

@VISHNU07
Below pattern working fine in Regex Builder -not sure why its not working while running workflow.

Hi @Fresher,

If you want to extract all the data between the keywords Table STH-1
NATIONAL STUDENT HOUSING MARKET and NATIONAL STUDENT HOUSING MARKET – SELECT SURVEY RESPONSES*, you can try the below -

Regex.Match(Your_Variable,"(?<=NATIONAL\sSTUDENT\sHOUSING\sMARKET\s\n)[\w+\d+\s\n*.,/&@()-–%$#*“”]+(?=NATIONAL STUDENT HOUSING MARKET – SELECT SURVEY RESPONSES*)").Value**

Thanks & Regards,
Apurba

Hi @Fresher

Try the attached workflowExtracttextusingregex.xaml (6.2 KB)
Do tell if its working :slight_smile:

Hi @apurba2samanta,

am fine with Regex Pattern, as highlighted in above post, is working fine in regex builder (Test text) - but in workflow am not getting any output

Hi @Fresher,

Fine. Can you please share your workflow consist of this Regex pattern?

Thanks & Regards,
Apurba

Hello @apurba2samanta
Please find the attached workflow

With below pattern am getting the match count as 1 , in regex builer ( test text) - values are getting highlighted and getting the output.

Blockquote(?sim)Market(.*)National.

With this below pattern am getting the match count as 0 , but in regex builer ( test text - Vaues are getting highlighted and not getting any output.

Blockquote (?<=Table STH-1\nNATIONAL STUDENT HOUSING MARKET)(.\n)+(.)(?=NATIONAL STUDENT HOUSING MARKET – SELECT SURVEY RESPONSES*)

regex.xaml (7.7 KB)