Regular Expression

This is a good site to test regex to use with QTP:

http://regexpal.com/

If our word is:

Ctrl

Regex=Ctrl

Or, ^Ctrl

Or, ^Ctrl$

Or, ^C…$

Or, C…

Or, ^C(?=trl)

Now, if the next word is:

Ctrl11

Regex= C.....

Or, ^C(?=trl)..* (works in http://tools.netshiftmedia.com/regexlibrary/# site, but does not work with the site mentioned at top).

Or, ^C* (does not work always)

Now, text: ctl11$sometext

Regex=
^ctl\d\d\$sometext

Or, ^c[a-z]{2}\d\d[a-z]+$

Now, [a-z]{2} is to get the letter ‘t’ and ‘l’. I need to be specific to QTP does not go and recognize anything else.

The other part, [a-z]+$

The + means, the letters must occur one or more time. So, it would fail if the text is “ctl11”

 

FOR DECIMAL:

Regex=^\d*[0-9](\.\d*[0-9])?$

If the number is 123.123

Regex=
^\d*\.\d*

Advertisement
  1. Leave a comment

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

%d bloggers like this: