Guys attached is the utility for various general Regular expressions
operations you can driectly use it in your code.
Hope it would helpful for you all..
Regards
Shalabh Dixit
On Tue, Jul 19, 2011 at 7:24 AM, Roman Zilber <[email protected]> wrote:
>
> Function RegExpTest(patrn, strng)
> Dim arr(), y
> y = 0
> Dim regEx, Match, Matches ' Create variable.
> Set regEx = New RegExp ' Create a regular expression.
> regEx.Pattern = patrn ' Set pattern.
> regEx.IgnoreCase = True ' Set case insensitivity.
> regEx.Global = True ' Set global applicability.
> Set Matches = regEx.Execute(strng) ' Execute search.
> For Each Match in Matches ' Iterate Matches collection.
> y = y +1
> For i=0 to Match.SubMatches.Count -1
> redim preserve arr(i+y)
> arr(y + i - 1) = Match.SubMatches(i)
> Next
> Next
>
> RegExpTest = arr
> End Function
>
>
> dim res: res= RegExpTest( "NO\.\s+([0-9]+)\s", "REQUEST NO. 0588 EQUEST
> NO. 0589 EQUEST NO. 0558 EQUEST NO. 058558 ")
>
>
> for i=0 to ubound (res) - 1
> msgbox (res(i))
> next
>
> On Mon, Jul 18, 2011 at 10:58 AM, MrB <[email protected]> wrote:
>
>> I can get the SOAP msg and I am including a sample msg.
>>
>> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/
>> envelope/ <http://schemas.xmlsoap.org/soap/envelope/>" xmlns:xsd="
>> http://www.w3.org/2001/XMLSchema"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>> - <soapenv:Body>
>>
>> .......
>>
>> END OF
>> REQUEST NO. 0588
>>
>> </soapenv:Body>
>> </soapenv:Envelope>
>>
>> I need to be able to get the request number from the XML so that I can
>> pass the variable elsewhere in my testing. Hope this makes sense.
>>
>> On Jul 17, 1:19 pm, Roman Zilber <[email protected]> wrote:
>> > In which format and way you get SOAP? It should be some kind of XML, do
>> you
>> > have it stored in variable, or you have web utility to get SOAP?
>> > ...
>> >
>> > Is something like that?
>> >
>> > http://mercuryquicktestprofessional.blogspot.com/2007/07/sending-soap.
>> ..
>> >
>> > So where is a problem, you can't get SOAP? can't parse number from it?
>> Don't
>> > know how to organize the code (where to save the plan numbers etc)?
>> > I really lost to understand the question, you can save all numbers in
>> array
>> > or in DataTable. like you do in any programming language.
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Fri, Jul 15, 2011 at 10:56 AM, MrB <[email protected]> wrote:
>> > > I thought my question was specific. There is a plan number that is
>> > > dynamic each time a plan is created. I need to grab this plan number
>> > > from the report and inject this number elsewhere.
>> >
>> > > On Jul 13, 8:05 pm, Roman Zilber <[email protected]> wrote:
>> > > > What is a question? "How do I do this?"
>> > > > Learn QTP and SOAP, once you have specific question, ask.
>> >
>> > > > On Wed, Jul 13, 2011 at 4:37 PM, MrB <[email protected]> wrote:
>> > > > > Hi all. First, let me say what we have. We create plans. Those
>> > > > > plans have numbers associated with them. Each time, the number is
>> > > > > different. I need to know how to grab this plan number from the
>> SOAP
>> > > > > report and then insert this plan number into another page we use
>> in
>> > > > > our application. How do I do this? I am a new user to QTP so my
>> > > > > skills are rather limited.
>> >
>> > > > > Thanks in advance!
>> >
>> > > > > --
>> > > > > You received this message because you are subscribed to the Google
>> > > > > "QTP - HP Quick Test Professional - Automated Software Testing"
>> > > > > group.
>> > > > > To post to this group, send email to [email protected]
>> > > > > To unsubscribe from this group, send email to
>> > > > > [email protected]
>> > > > > For more options, visit this group at
>> > > > >http://groups.google.com/group/MercuryQTP?hl=en
>> >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> > > "QTP - HP Quick Test Professional - Automated Software Testing"
>> > > group.
>> > > To post to this group, send email to [email protected]
>> > > To unsubscribe from this group, send email to
>> > > [email protected]
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/MercuryQTP?hl=en
>>
>> --
>> You received this message because you are subscribed to the Google
>> "QTP - HP Quick Test Professional - Automated Software Testing"
>> group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/MercuryQTP?hl=en
>>
>
> --
> You received this message because you are subscribed to the Google
> "QTP - HP Quick Test Professional - Automated Software Testing"
> group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/MercuryQTP?hl=en
>
--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en
''=====================================================================================================================================================================
'''Function to check if a string matches a Regular Expression Pattern
''=====================================================================================================================================================================
Function IsRegExMatch(strText, regEx_Pattern, blnMatchCompleteString)
Dim oRegExp, retVal
' Create regular expression object.
Set oRegExp = New RegExp
'Set pattern.
oRegExp.Pattern = regEx_Pattern
'Ignore case
oRegExp.IgnoreCase = True
'Match complete string or not
oRegExp.Global = blnMatchCompleteString
'Test the regular expression
IsRegExMatch = oRegExp.Test(strText)
Set oRegExp = Nothing
End Function
''=====================================================================================================================================================================
'''Function to Match a Regular Expression and Replace with a particular text if
a string matches a regular expression pattern.
''=====================================================================================================================================================================
Function
RegExMatchandReplace(strText,regEx_Pattern,strReplacementText,blnMatchCompleteString)
Dim oRegExp, retVal,strReplacedText
' Create regular expression object.
Set oRegExp = New RegExp
'Set pattern.
oRegExp.Pattern = regEx_Pattern
'Ignore case
oRegExp.IgnoreCase = True
'Match complete string or not
oRegExp.Global = blnMatchCompleteString
'Test the regular expression
RegExMatch = oRegExp.Test(strText)
If RegExMatch = True Then
strReplacedText =
oRegExp.Replace(strText,strReplacementText)
End If
RegExMatchandReplace = strReplacedText
Set oRegExp = Nothing
End Function
''=====================================================================================================================================================================
'''Function to Get Total Number of Matches of a Regular Expression Pattern in a
particular string
''=====================================================================================================================================================================
Function GetRegExMatchCount(strText, regEx_Pattern, blnMatchCompleteString)
Dim oRegExp, retVal
'Create regular expression object.
Set oRegExp = New RegExp
'Set pattern.
oRegExp.Pattern = regEx_Pattern
'Ignore case
oRegExp.IgnoreCase = True
'Match complete string or not
oRegExp.Global = blnMatchCompleteString
'Test the regular expression
RegExpMatch = oRegExp.Test(strText)
If RegExpMatch Then
Set oRegExMatchCount = oRegExp.Execute(strText)
GetRegExMatchCount = oRegExMatchCount.Count
End If
Set oRegExp = Nothing
End Function
''=====================================================================================================================================================================
'''Function to Trim white space characters from end of a string
''=====================================================================================================================================================================
Public Function RTrimW(ByVal Text)
'String pattern ending with carriage return, tab, new line or a
space character
RTrimPattern = "[\s]*$"
Dim oRegExp
Set oRegExp = New RegExp
oRegExp.Pattern =RTrimPattern
oRegExp.Global = False
RTrimW = oRegExp.Replace(Text,"")
Set oRegExp = Nothing
End Function
''=====================================================================================================================================================================
'''Function to Trim white space characters from start of a string
''=====================================================================================================================================================================
Public Function LTrimW(ByVal Text)
'String pattern ending with carriage return, tab, new line or a
space character
LTrimPattern = "^[\s]*"
Dim oRegExp
Set oRegExp = New RegExp
oRegExp.Pattern = LTrimPattern
oRegExp.Global = False
LTrimW = oRegExp.Replace(Text,"")
Set oRegExp = Nothing
End Function
''=====================================================================================================================================================================
''Function to Trim white space characters from both start and end of a string
''=====================================================================================================================================================================
Public Function TrimW(ByVal Text)
TrimW = LTrimW(RTrimW(Text))
End Function