Find a Matching Pattern in String Using Regular Expression in UFT

Regular Expression Find matching Pattern

The regular expression or RegEx is a very powerful tool to find a matching pattern of string in a given string or find a substring in a string. In this article, I will show you how to use regular expression in UFT to check whether any MASTER or a VISA card account number is present in a given string. You can use this example to do similar kinds of things.

Regular Expression to find a matching pattern of String

A Master or Visa card is a 16 digit number. A Visa Card starts with the number 4 and a Master Card starts with 5. The rest of the numbers could be anything between 0 to 9. The following function will find all matching card numbers in the given string.

In the variable strVar a string value has been stored containing two Master Card Numbers.
I am calling the GetAllMatchingCard() function that would display the position and values of the Master cards in the string.

The output would be as follows.

Matching pattern UFT

A couple of points to be remembered. If you are searching a text value within a string then set the following things to regEXP object.

When to use the Regular Expression in String Manipulation

There could be a number of instances like

Leave a Reply