Matching Characters Using Regular Expressions in QTP in Testing

Let us now learn how to match characters using Regular Expressions.

regular-expression-parameter.png

Matching Any Single Character

If we want to match a single character then a period (.) instructs QuickTest to search for any single character. For example, welcome matches welcomed, welcomes, or welcome followed by any other single character or by a space.

match-single-character-period.jpg

Matching Zero or More Specific Characters

If we want to match zero or more specific characters then an asterisk (*) instructs QuickTest to match zero or more occurrences of the preceding character. e.g.:- ca*t matches cat, caaaat, and ct.

Matching any single character in a list

If we want to match a single character from a list then Square Brackets can be used to instruct QuickTest to search for any single character from a list. For example, 193[234] can be used to search for a date 1932, 1933 or 1934.

match-character-within-list.jpg

Matching any single character not in a list

If we want to match a single character which is not in a list then (^) as a first character can be used to instruct QuickTest to match the character from the list except for the ones that are specified in the string. For example, [^gh] matches all the character except g and h.

Matching a single character within a range

If we want to match a single character within a range then Square Brackets ([]) along with hyphen (-) can be used. For example, order no [1-18] can be used to match  the order from 1 to 18.

match-character-within-range.jpg