Using Regular Expressions in selectors

Hi,

I want to use regular expression in a selector.I want to match spaces after innertext. Lets say we have 2 buttons with innertext=’ button ’ and innertext=’ button test ’ I want to use innertext in selector so when I can pass innertext as a parameter and when button is passed its selecting the correct control. if I am using argument called in_InnertText, how to allow only spaces after the text? in the following, how to use a regular expression after in_InnertText?

innertext=‘“+in_InnertText+”’

Thanks!

use wild cards in selectors.

Rather we can mention like this
innertext=’ " + in_InnertText + "*’

Star next to this variable having a value will take any character including blank space

Cheers @Asiri

I want to match SPACES only, the RegEx should not match for any other characters.

Update few examples so we can have clear picture of how many spaces

hi ab00333721,

I have 2 buttons with innertext,

’ button ’ (5 spaces)
’ button test ’ (5spaces)

If I use button , selector doesn’t work because it matchs both.I need to pass inner text as a parameter in_Innertext and use a regular expression to match spaces so when I pass “button” it will match the first and “button test” it will match the second

If it were me, I would have the in_InnerText variable with exactly what you want. This means the regex should be done before it gets to the selector portion. Separating it out makes it more clear what is happening for debugging and for future people looking at the code.

To do this, just manipulate in_InnerText before hand with regex. I’m still not 100% clear what you’re trying to do, but \s will grab any white-space characters. Use an earlier if statement to decide whether to assign in_InnerText to button vs button test and you can simply pass in the one variable into your selector exactly the way you’ve written it: innertext='"+in_InnertText+"'

Regular expressions can be used in selectors as shown in below link