How to use regular expressions in UiPath


#1

Hi everybody,

I’m scraping information from an application and I have each time a string like “You have (400.65 points)”, but it can be also 34.90 or 4059.56, so I tried to scrap each time the number with a regular expression:

Regex.Match(OCRStringOutput, @"^0-9?$").Value

But this expression don’t work. Have you an idea to extract each time only the number from the string?

Thanks,


#2

Try this (probably could be made better, I’m not a big fan of regex):

Regex.Match(sampleString, “([0-9]).+([0-9])”).Value

Your original expression would translate to something that doesn’t match your input:
From beginning of string match character 0 then - then one-or-more 9 then end of string.

Also the @ sign is not needed, that’s from C# to mark a string literal (to not need to escape special chars).

Regards.


#3

Hello nSangui, I guess we need more information. Please let me know why are you scrapping:

is it because it’s a citrix enviroment?

have you tried to use find relative image option when there is no selector available?

you can click on find image find the relative element of the value you are trying to get, for example “score” and then use relative reference to scrap the value.

Regards.


#4

Hi @andrzej.kniola, I use regex extensively for extracting data from non structured files, and to be honest it’s the only method I know. You said you are not a big fan of regex. I am curious what method do you use to extract data from non structured files, emails, etc ?

Thanks
Gary


#5

Hi everybody, thanks for your answers!!

The environment where I’m working is a java application, and the complete sentence is “Career HSSE : (2345.65 point(s) HSSE)”, but UiPath identifies the section where the sentence is as an image.

I scrap because I want to extract this number to compare with another scraped from another application.

I extracted all the sentence and I’m trying to use the Regex to extract this double that changes every time (I need to compare some numbers), but I’ll also try the find relative one more time (I’ve tried, but didn’t work I think)


#6

Hi,

I have a followup-question: How do I use this type of expression in UiPath? (e.g. Regex.Match(somestring, @"\d+").Value)
I have tried to use this directly in an Assign activity, but I am not able to run it:

“Compiler error(s) encountered processing expression “Regex.Match(somestring, @”\d+”).Value". Expression expected."

Should I have used the “Invoke method” instead? If so, can someone point to a user guide for how to use this please?


#7

You can use the Matches activity.


How to get sub-string from string-data, where sub-string is dynamic each time when it loads on a webpage?
#8

Hi,

you can try this flow,gmail from string.xaml (10.2 KB)


#9

If anyone is still looking for a solution, just use the activity “Matches” in UiPath, just as @andraciorici suggested.
As for the regex to be used for the above problem, use the following: “\b\d+.\d{2}\b”


#10

Hi,
Can someone help me write regex from the attached screenshot? I need only the value(i.e after colon

) of Metric name, Service name and Time


#11

Please check the output Pane.


#12

Hi @Neha2111,

Refer this post.

Regards,
Arivu


#13

Hi, Can you help me with this -

From the screenshot, I want only ECS Cpu Utilization , the given service name (i.e after colon and just before clusterName) and time.

image


#14

Hi @Neha2111,

Get Metric value:
Use Matches activity
Properties
Input : strvalue
Pattern : ((?<=Metric name:).*(?=ServiceName::))
Result: iEnumResult ->IEnumberable
after that use assign activity to get the data
strMetric =iEnumResult (0).ToString()

Regards,
Arivu


#15

when I use Regex it is coming as not declared should I download any specific library to use that


#16

@harinathreddy.yn,Go to imports and import namespace system.text.regularexpressions


#17

I tried that, but I am unable to find it.


#18

@harinathreddy.yn,rg


#19

@arivu96 hi . i wanted to ask you if i want to get all the matches and store them in an array of strings , how would i do that? For example: arrStrmetric = ? ;


#20

Hi @Alex_Risteiu,

Refer the above example

So iEnumResult is IEnumerable dataType.

you can use the Foreach activity to loop through the data.

Regards,
Arivu