Thursday 21 November 2013

What are the metacharacters (special characters ) in regular expressions in QTP?

Below is the list of all meta characters in QTP.


\ -  indicates that the next character would be a special character, a literal or a backreference

^  - Input String should be matched at the beginning.

$  - Input String should be matched at the end.

*  - Matches the preceding character zero or more times. It is same as {0,}.

+  -  Matches the preceding character one or more times.  It is same as {1,}.

?   - Matches the preceding character zero or one time.  It is same as {0,1}

{i} - Matches the previous character exactly i times.

{i,} - Matches the previous character at least i times and at most any time.

{i,j} -Matches the previous character at least i times and at the most j times.

.     -  Matches any single character except "\n".

(pattern) -  Matches pattern and captures the match that can be used in backreferences.
 p|q  -  Matches either p or q. Please note that p and q could be more complex regular expressions

[pqr]  - A character set. Matches any one of the character inside the brackets.

[^pqr]  - A negative character set. Matches any character not inside the brackets.

[p-z]   -  A range of characters. Matches any character in the specified range i.e p,q,r,....x,y,z.

[^p-z]  -  A negative range characters. Matches any character not in the specified range i.e. a,b,c...m,n,o 

\b      -  Matches the boundary of the word

\B      -  Matches middle part of the word.

\d      -  Matches a digit character. same as [0-9].

\D      -  Matches a nondigit character. same as  [^0-9].

\f , \n and \r     -  Matches a form-feed character, newline and carriage character.

\s    - Matches any white space character including space, tab, form-feed. Equivalent to [ \f\n\r\t\v].

\S      - Matches any non-white space character. Equivalent to [^ \f\n\r\t\v].

\t  , \v   - Matches a horizontal and  vertical tab character.

\w      - Matches alpha numeric character including underscore. Equivalent to '[A-Za-z0-9_]'.

\W      - Matches any non - alpha numeric character. Equivalent to '[^A-Za-z0-9_]'.

\number- A reference back to captured matches.

**********************************************************************************

**********************************************************************************

Some examples on regular expressions:
  1. To match the 10 digit mobile number ->  \d{10}
  2. To match email address  -> \w+@\w+\.\w+
You can use regular expression evaluator introduced in QTP 11 to test above regular expressions.

You may also like below topics on regular expressions in QTP.
  1. Regular Expressions in OR in QTP.
  2. Regular Expressions in descriptive programming in QTP.
  3. Regular expression evaluator in QTP.
  4. Meta characters in regular expressions.
  5. Case insensitive regular expressions in QTP.
  6. Regexp object in QTP.
  7. Global Property in Regular Expressions
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.