Selenium Pattern Matching using Regular expressions

Selenium Pattern Matching using Regular expressions


Selenium Regular Expression patterns are the most frequenty used and the most useful.

The regular expression pattern in Selenium is similar to that offered by Javascript. In order to use the regular expression, you will need to prefix each of these with regexp: or regexpi:


To test if a particular string contains our text, we can do so in the following manner.


let’s verify if an input field contains the string ‘Abhilash Gopi‘.


The input field is identified as strName

Command Target Value
ClickAndWait Link=Search  
verifyValue Id=strName Regexp:[Aa]bhilash [Gg]opi


What does the value regexp indicate?

You will notice here that the regexp is given as [Aa]bhilash [Gg]opi

It means that the resultant text could be found as “abhilash gopi” or “Abhilash Gopi” or “Abhilash gopi” or “abhilash Gopi”, in whatever form it could be with either A and/ or G in uppercase or lowercase.

I hope you get this well.

Your typical regular expression for email verification would be given as


Another one would go like this

Regexp: ^([a-zA-Z0-9_\-\.]+)@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$

Regular expression to verify generic URL


Published by Abhilash Gopi

Am a simple guy, loves to see the smiles on my friend's faces. So what are you waiting for? Be my friend, Guys n Gals.

2 thoughts on “Selenium Pattern Matching using Regular expressions

  1. Please help me to write one regexp:

    here, can I use – (“nu*”)).click(); – I added a star next to the letter ‘u’.
    For fields identified by css, it seems the * regexp not working. Am I correct?

    How can I use the regexp above in the code below:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: