Techniques Using Regular Expressions:
Techniques Using Regular Expressions:
'To use Regular Expressions in scripting first we should create Instance of Regular Expression Class.
Set SampleRegExP = New RegExp
'Set the Search Pattern (Regular Expression)
SampleRegExP.Pattern= “H.*”
'Specify the Case Sensitivity is true or false
SampleRegExP.IgnoreCase= False
'Specify required search results (True is for all search Results, False is for only one)
SampleRegExP.Global=True
'Execute Search conditions on a main string
Set Matches = SampleRegExP.Execute(“Hi How Are You”)
'Get the results by using a For Loop
For Each Match in Matches
Msgbox Match.FirstIndex
Msgbox Match.Value
Next
Set SampleRegExP = Nothing
Script to extract a substring from a string based upon a pattern:
rExpression="H."
MainString="Hi How Are You"
Set SampleRegExP = New RegExp
SampleRegExP.Pattern= rExpression
SampleRegExP.IgnoreCase= False
SampleRegExP.Global=True
Set Matches = SampleRegExP.Execute(MainString)
For Each Match in Matches
Msgbox Match.FirstIndex
Msgbox Match.Value
Next
Set SampleRegExP = Nothing
'Script to Replace string:
rExpression="H."
MainString="Hi How Are You"
ReplacedString= "Hello"
Set SampleRegExP = New RegExp
SampleRegExP.Pattern= rExpression
SampleRegExP.IgnoreCase= False
SampleRegExP.Global=True
Msgbox SampleRegExP.Replace (MainString,ReplacedString)
Set SampleRegExP = Nothing
Script to Test a string existence:
rExpression="H."
MainString="Hi How Are You"
Set SampleRegExP = New RegExp
SampleRegExP.Pattern= rExpression
SampleRegExP.IgnoreCase= False
SampleRegExP.Global=True
retVal = SampleRegExP.Test(MainString)
If retVal Then
Msgbox "One or more matches were found."
Else
Msgbox "No match was found."
End If
Set SampleRegExP = Nothing
'To use Regular Expressions in scripting first we should create Instance of Regular Expression Class.
Set SampleRegExP = New RegExp
'Set the Search Pattern (Regular Expression)
SampleRegExP.Pattern= “H.*”
'Specify the Case Sensitivity is true or false
SampleRegExP.IgnoreCase= False
'Specify required search results (True is for all search Results, False is for only one)
SampleRegExP.Global=True
'Execute Search conditions on a main string
Set Matches = SampleRegExP.Execute(“Hi How Are You”)
'Get the results by using a For Loop
For Each Match in Matches
Msgbox Match.FirstIndex
Msgbox Match.Value
Next
Set SampleRegExP = Nothing
Script to extract a substring from a string based upon a pattern:
rExpression="H."
MainString="Hi How Are You"
Set SampleRegExP = New RegExp
SampleRegExP.Pattern= rExpression
SampleRegExP.IgnoreCase= False
SampleRegExP.Global=True
Set Matches = SampleRegExP.Execute(MainString)
For Each Match in Matches
Msgbox Match.FirstIndex
Msgbox Match.Value
Next
Set SampleRegExP = Nothing
'Script to Replace string:
rExpression="H."
MainString="Hi How Are You"
ReplacedString= "Hello"
Set SampleRegExP = New RegExp
SampleRegExP.Pattern= rExpression
SampleRegExP.IgnoreCase= False
SampleRegExP.Global=True
Msgbox SampleRegExP.Replace (MainString,ReplacedString)
Set SampleRegExP = Nothing
Script to Test a string existence:
rExpression="H."
MainString="Hi How Are You"
Set SampleRegExP = New RegExp
SampleRegExP.Pattern= rExpression
SampleRegExP.IgnoreCase= False
SampleRegExP.Global=True
retVal = SampleRegExP.Test(MainString)
If retVal Then
Msgbox "One or more matches were found."
Else
Msgbox "No match was found."
End If
Set SampleRegExP = Nothing
Comments
Post a Comment