Wednesday 20 November 2013

Explain RegExp Object in QTP

RegExp is a very important object in QTP that can be used to find the patterns in given string using regular expressions.

This object can be created using below syntax.
 Set regExpObject = New RegExp  

RegExp Object supports below properties.

Global Property     - a pattern should match all occurrences in string or just the first one
IgnoreCase Property - specifies if the search is case-sensitive or not
Pattern Property    - Sequence of literal characters and special characters (Meta Characters like *,?,+,\b,\d,\n etc)

RegExp Object supports below methods.

Test Method     - returns true if the pattern is found in the given string
Execute Method  - returns a Matches collection containing a Match object(having properties firstindex and value) for each match found in string.
Replace Method  - replaces the matched values in the given string by another value


Sample Example on Execute method.

'*******************************************************
 Set regExpObject = New RegExp  
  search_string = "MS dhoni is very lucky cricketer"
  regExpObject.Pattern = "lucky"

  regExpObject.Ignorecase = true
  regExpObject.Global = true
 
 Set matches  = regExpObject.execute(search_string)

 For each match in matches
print  match.firstIndex & " - " & match.value
 Next
'*******************************************************
In above example we are trying to find the pattern "lucky" in the given string "MS dhoni is very lucky cricketer". We are also printing the position where the match is found.

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.