We can easily verify text, elements by Selenium IDE. In my applicatiion there is long date shown. This is how I make sure my date format is ok and shown in correct format.

Note: some part of above image is blurred. 

Here is the explanation:

\w{6,9} = it checks Saturday - Friday. Wednesday is the longest one which has 9 characters and smallest one has 6 characters.

\w{3} = it checks the month in 3 character. Jan, Feb, Mar - Dec.

\d{2} = it checks the date in 2 digits format. You can see that in application it is show 01, not 1.

\d{4} = it checks the year in 4 digits.


ashek's picture

The example regex will consider the following strings as valid date:
9999999, 999 99, 9999
friday, jan 01, 2010
.. and so on..

Its because "\w" represents any string or number. We can make the filter tighter by providing options for our known values to choose from. So, a better regex would be:

(Saturday|Sunday|Monday|Tuesday|Wednesday|Thursday|Friday), (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (0[1-9]|[12][0-9]|3[01]), (19|20)\d\d

Corresponding Java string would be:

"(Saturday|Sunday|Monday|Tuesday|Wednesday|Thursday|Friday), (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (0[1-9]|[12][0-9]|3[01]), (19|20)\\d\\d"


  • (Saturday|Sunday|Monday|Tuesday|Wednesday|Thursday|Friday) - only one from these 7 defined values
  • (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) - only one from these 12 values
  • (0[1-9]|[12][0-9]|3[01]) - 01to09 or 10to29 or 30 or 31. That is from 01-31
  • (19|20)\\d\\d - starting number would be 19 or 20 and then two random digits.


Here is an online tool for regex testing:


shiblee's picture

That is great Ashek and thanks a lot for making is more accurate. Here I've updated my script:

Later on I'll do some more tweaking.

Add new comment