#FeatureBlog - 19.10 - Using regular expression (Regex) in the selector attributes

Nope, unfortunately.

how can I use OR condition in regular expression and use that regex in Selectors.

in My case I want to click on an object which has
title=^Archiv* OR ^Search*
how can I achieve this.
I am using title=‘^Archive*|^Search*’
is this correct?

Hi @sanjeev.sapre

I have a Regex MegaPost aimed at new users. Hopefully this can help you.

Regex help tutorial MEGAPOST – Making your first Regex post, Reusable Regex Patterns, Regex Troubleshooting, Sample Workflow and more

Cheers

1 Like

I’m having a need to use Regex Selectors. But I’m unable to make the selector return multiple elements. It returns just the first match. I have confirmed that all selectors are identical and can be captured by matching with an expression on parentid attribute.

I have tested it on an online regex editor, and I see that the expression matches multiple selectors:

But when the automation runs, only the first match element is returned.

What am I doing wrong?

thanks!

@AndyMenon - what is the code your are using for print the regex output?

Hi @prasath17,

I’m using a GetText activity and returning the value into a variable and printing it out.

Thanks

@prasath17 - did this answer your question? If not I can send screen grabs of what I’m trying to do when I get back to my desk.

thanks

@AndyMenon - That would be helpful.

I cannot show my actual business problem, but here is a similar situation I’m trying to replicate in public using Google finance. I’m trying to extract text from the 6 DIVs.

The first step for me is to have a REGEX selector that can match all of the 6 DIVs. Once I have those, I can loop through each of the inside text and use standard Regex operations to extract parts of the information I need.

Here is the Selector for the first DIV #1 and the last DIV #6. As you can see, that they fit a pattern.

<webctrl css-selector='body&gt;c-wiz&gt;div&gt;div&gt;div&gt;div&gt;div&gt;c-wiz&gt;div&gt;section&gt;div&gt;a&gt;div&gt;div' idx='1' parentid='yDmH0d' tag='DIV' />

<webctrl css-selector='body&gt;c-wiz&gt;div&gt;div&gt;div&gt;div&gt;div&gt;c-wiz&gt;div&gt;section&gt;div&gt;a&gt;div&gt;div' idx='6' parentid='yDmH0d' tag='DIV' />

I have confirmed this with a basic text comparison as shown below, both selectors are the same except for their idx values:

And here is my Regex Selector - in my previous post I showed that the regex does seems like it is working when I test it in a Regex Editor and it also validates in UiExplorer.

<webctrl css-selector='body&gt;c-wiz&gt;div&gt;div&gt;div&gt;div&gt;div&gt;c-wiz&gt;div&gt;section&gt;div&gt;a&gt;div&gt;div' parentid='(yDmH0d)' tag='DIV' matching:parentid='regex'/>

The Automation does not fail, it runs and returns text only from the first matching DIV ( the BETW Stock ticker symbol) . I was expecting it to return a large text containing text from all of the DIVs that could later be split and processed.

image

Thanks and let me know if I’m missing something.

Ok, so this is interesting and confusing now. And now I’m wondering if I’ve understood this entire subject correctly! I tried an alternate approach, and this time I got a failure.

I tried to write a Regex on the idx attribute of the selector to look for all tags between idx=‘1’ and idx=‘6’ like so:

<webctrl css-selector='body&gt;c-wiz&gt;div&gt;div&gt;div&gt;div&gt;div&gt;c-wiz&gt;div&gt;section&gt;div&gt;a&gt;div&gt;div' idx='[1-6]{1}' parentid='yDmH0d' tag='DIV' matching:idx='regex' />

But I can’t figure out why the Robot is looking for idx=‘0’ when I have specified the range [1-6] in my Regex. This is causing a failure obviously .

But the good thing is it knows that there are 6 elements that can be matched. If that is so, why is my earlier Regex on parentid not working? And if the Robot knows about the 6 other matches, why is it wasting it’s time by trying to find idx=‘0’ that it is not supposed to look for in the first place, and then failing?

image

@AndyMenon

If you want all elements matching your selector, use FindChildren activity to get them. If your selector can match multiple elements and you’re relying on an activity expected to return one element, you’ll get the first match only.

1 Like

@AndyMenon , instead of bracket in “idx”, you can use () bracket. This may help you.

Regards,
Nirmalya Sarkar.

Thanks @nirmalya.sarkar!

I will give this a shot the next time I have to use the RegEx selector.

:slight_smile:

@AndyMenon , if it is working for you, please click on solution button.

Regards,
Nirmalya Sarkar.

Hi @loginerror,

Quite late to the party, but this is extactly what I was looking for. RegexSearch within selectors. BluePrism had this feature long ago so its nice to see UiPath support it too.

The windows popup in different languages is different. By using the following alteration to the selector we avoided drastic changes to the code!

If anyone else is facing the same issue, only a | is required to support multiple languages.

<wnd app='chrome.exe' cls='#32770'  title='Open|Åpne' matching:title='regex'  />
<wnd ctrlid='1148' />
4 Likes

Hi @loginerror

Can we add flags to the regular expression?

Thanks In Advance

Hi @Rohan_Tammewar

So far, we only support the case sensitivity flag. Can you please describe your use case and what RegEx flags would you consider useful?

Thanks,
Iulian Mircea

Can you please share us the full workflow so that beginners like me can learn.

Thanks
Someswaran

Hi @iulian.mircea

The case was related to the multiline, single line and case sensitive flags. I have checked the case sensitivity flag link but not sure how to use it in selector, an eg could be of great help.

Thanks,
Rohan Tammewar

Hi all,

Thanks for sharing your feedback and suggestions for improvement!

Regarding case-insensitive RegEx matching, here is an example of how to use it for "innertext" webctrl attribute:

<html app='chrome.exe' title='HTML Tutorial' url='https://www.w3schools.com/html/default.asp' />
<webctrl tag='H1' innertext='.*html.*tutorial.*' matching:innertext='regex' casesensitive:innertext='false' />

This selector will match an H1 element with text "HTML Tutorial". If you switch casesesnsitive:innertext to true, it won’t match anymore.

Regarding singleline and multiline support, we don’t have it at the moment, but usually there are alternative ways to design Regular Expressions which work around this limitation. Can you please share a use case for singleline or multiline RegEx, so we can look for such a workaround?

Best regards,
Iulian

2 Likes