• RSS
  • Facebook
  • Twitter

One Center for all the Testing Need. OneTestingCenter is for all, for all QA, for all Automation. Automation is easy, fun and enriching experience. Happy Learning and Happy Testing!

  • Access to All QA

    At OneTestingCenter, you find lots of books,articles,blogs and detailed guides. Everyone has access to QA. Happy Learning, Happy Testing.

  • Global Trainings

    All the QA/Auotmation trainings are available at OneTestingCenter. QA, Automation, QTP/UFT, Selenium, LoadRunner, QC/ALM, Appium...

  • Automation Learning Fun

    Technology is always evolving. Automation is always challenging. To be frank, Automation is fun, enthusiastic and enrching experience.

    'RegExp
     Method
    Dim strRet
    ' create regular expression object
    Set objRegEx = New RegExp
    ' set the pattern
    objRegEx.Pattern = strPattern
    ' set it be not case sensitive
    objRegEx.IgnoreCase = True
    ' set global flag =true sothat we search all of the string, instead of just searching  for the first occurrence
    objRegEx.Global = True
    ' execute search
    Set strMatches = objRegEx.Execute(strString)
    '=====================================================

    'Execute Method
    '####################################################
    ' @ Executing a regular expression to find text within a string.
    '####################################################
    MsgBox RegularExpExample("QTP.", "QuickTestQTP, by GAReddy and QuickTestQTP is qtp's blog")
    ' =============================================================
    ' @Function: RegularExpExample
    ' @Desc :    Example of how to use the regular expression object to find text within a string
    ' @Params :  strPattern is the regular expression
    '            strString is the string to use the expression on
    ' @Returns : An example string showing the results of the search
    ' =============================================================
    Function RegularExpExample(strPattern, strString)
    Dim objRegEx, strMatch, strMatches
    Dim strRet
    ' create regular expression object
    Set objRegEx = New RegExp
    ' set the pattern
    objRegEx.Pattern = strPattern
    ' set it be not case sensitive
    objRegEx.IgnoreCase = True
    ' set global flag =true sothat we search all of the string, instead of just searching  for the first occurrence
    objRegEx.Global = True
    ' execute search
    Set strMatches = objRegEx.Execute(strString)
    ' for each match
    For Each strMatch in strMatches
       strRet = strRet & "Match found at position '" & _
                strMatch.FirstIndex & "' - Matched Value is '" & _
                strMatch.Value & "'" & vbCRLF
    Next
    RegularExpExample = strRet
    End Function ' RegularExpExample

    'Test Method
    '########################################################################
      '@Using Locate to determine if specific text exists within a string.
     '#######################################################################
    MsgBox LocateText("www.QuickTestQTP.blogpsot.com", "QTP")
    MsgBox LocateText("www.QuickTestQTP.blogpsot.com", "QTP.*.com")
    ' =============================================================
    ' @Function: LocateText
    ' @Desc :    Uses a regular expression to locate text within a string
    ' @Params :  strString is the string to perform the search on
    '            strPattern is the regular expression
    ' @Returns : True if the pattern was found, False otherwise
    ' =============================================================
    Function LocateText(strString, strPattern)
    Dim objRegEx
    ' create the regular expression
    Set objRegEx = New RegExp
    ' set the pattern
    objRegEx.Pattern = strPattern
    ' ignore the casing
    objRegEx.IgnoreCase = True
    ' perform the search
    LocateText = objRegEx.Test(strString)
    ' destroy the object
    Set objRegEx = Nothing
    End Function ' LocateText

    'Replace Method
    '#################################################################
      '@Using the replace method to find and replace text in a string.
     '#################################################################
    MsgBox ReplaceText("QuickTest QTP: Learning QTP is easy .", "easy.", "easiest")
    MsgBox ReplaceText("QTP seems to be  easy .Just look here, everything else about QTP exists: but implemenation is HARD...!","but.*","!")
    ' =============================================================
    ' @Function: ReplaceText
    ' @Desc :    Uses a regular expression to replace text within a string
    ' @Params :  strString is the string to perform the replacement on
    '            strPattern is the regular expression
    '            strReplacement is the replacement string
    ' @Returns : ReplaceText
    ' =============================================================
    Function ReplaceText(strString, strPattern, strReplacement)
    Dim objRegEx
    ' create the regular expression
    Set objRegEx = New RegExp
    ' set the pattern
    objRegEx.Pattern = strPattern
    ' ignore the casing
    objRegEx.IgnoreCase = True
    ' make the replacement
    ReplaceText = objRegEx.Replace(strString, strReplacement)
    ' destroy the object
    Set objRegEx = Nothing
    End Function ' ReplaceText


    Reactions:

    QTP – Regular Expressions

    'RegExp
     Method
    Dim strRet
    ' create regular expression object
    Set objRegEx = New RegExp
    ' set the pattern
    objRegEx.Pattern = strPattern
    ' set it be not case sensitive
    objRegEx.IgnoreCase = True
    ' set global flag =true sothat we search all of the string, instead of just searching  for the first occurrence
    objRegEx.Global = True
    ' execute search
    Set strMatches = objRegEx.Execute(strString)
    '=====================================================

    'Execute Method
    '####################################################
    ' @ Executing a regular expression to find text within a string.
    '####################################################
    MsgBox RegularExpExample("QTP.", "QuickTestQTP, by GAReddy and QuickTestQTP is qtp's blog")
    ' =============================================================
    ' @Function: RegularExpExample
    ' @Desc :    Example of how to use the regular expression object to find text within a string
    ' @Params :  strPattern is the regular expression
    '            strString is the string to use the expression on
    ' @Returns : An example string showing the results of the search
    ' =============================================================
    Function RegularExpExample(strPattern, strString)
    Dim objRegEx, strMatch, strMatches
    Dim strRet
    ' create regular expression object
    Set objRegEx = New RegExp
    ' set the pattern
    objRegEx.Pattern = strPattern
    ' set it be not case sensitive
    objRegEx.IgnoreCase = True
    ' set global flag =true sothat we search all of the string, instead of just searching  for the first occurrence
    objRegEx.Global = True
    ' execute search
    Set strMatches = objRegEx.Execute(strString)
    ' for each match
    For Each strMatch in strMatches
       strRet = strRet & "Match found at position '" & _
                strMatch.FirstIndex & "' - Matched Value is '" & _
                strMatch.Value & "'" & vbCRLF
    Next
    RegularExpExample = strRet
    End Function ' RegularExpExample

    'Test Method
    '########################################################################
      '@Using Locate to determine if specific text exists within a string.
     '#######################################################################
    MsgBox LocateText("www.QuickTestQTP.blogpsot.com", "QTP")
    MsgBox LocateText("www.QuickTestQTP.blogpsot.com", "QTP.*.com")
    ' =============================================================
    ' @Function: LocateText
    ' @Desc :    Uses a regular expression to locate text within a string
    ' @Params :  strString is the string to perform the search on
    '            strPattern is the regular expression
    ' @Returns : True if the pattern was found, False otherwise
    ' =============================================================
    Function LocateText(strString, strPattern)
    Dim objRegEx
    ' create the regular expression
    Set objRegEx = New RegExp
    ' set the pattern
    objRegEx.Pattern = strPattern
    ' ignore the casing
    objRegEx.IgnoreCase = True
    ' perform the search
    LocateText = objRegEx.Test(strString)
    ' destroy the object
    Set objRegEx = Nothing
    End Function ' LocateText

    'Replace Method
    '#################################################################
      '@Using the replace method to find and replace text in a string.
     '#################################################################
    MsgBox ReplaceText("QuickTest QTP: Learning QTP is easy .", "easy.", "easiest")
    MsgBox ReplaceText("QTP seems to be  easy .Just look here, everything else about QTP exists: but implemenation is HARD...!","but.*","!")
    ' =============================================================
    ' @Function: ReplaceText
    ' @Desc :    Uses a regular expression to replace text within a string
    ' @Params :  strString is the string to perform the replacement on
    '            strPattern is the regular expression
    '            strReplacement is the replacement string
    ' @Returns : ReplaceText
    ' =============================================================
    Function ReplaceText(strString, strPattern, strReplacement)
    Dim objRegEx
    ' create the regular expression
    Set objRegEx = New RegExp
    ' set the pattern
    objRegEx.Pattern = strPattern
    ' ignore the casing
    objRegEx.IgnoreCase = True
    ' make the replacement
    ReplaceText = objRegEx.Replace(strString, strReplacement)
    ' destroy the object
    Set objRegEx = Nothing
    End Function ' ReplaceText