Can somebody give me few examples for using regular expression?

Questions by priyaspve

Showing Answers 1 - 2 of 2 Answers

kvvsatish

  • Jul 21st, 2006
 

The following example is used to identify numbers in the input givenSet reg=new regexpreg.pattern="d+"reg.global=truereg.ignorecase=trueSet m=reg.execute("This is India 2006 and I am proud to be an INDIAN 999")For each n in m msgbox n.valueNextEven regular expressions are used in check points and string replacing functions

  Was this answer useful?  Yes

madhavi

  • Jul 26th, 2006
 

The following code illustrates how to obtain a SubMatches collection from a regular expression search and how to access its individual members:

Function SubMatchTest(inpStr)  Dim oRe, oMatch, oMatches  Set oRe = New RegExp  ' Look for an e-mail address (not a perfect RegExp)  oRe.Pattern = "(w+)@(w+).(w+)"  ' Get the Matches collection  Set oMatches = oRe.Execute(inpStr)  ' Get the first item in the Matches collection  Set oMatch = oMatches(0)  ' Create the results string.  ' The Match object is the entire match - dragon@xyzzy.com  retStr = "Email address is: " & oMatch & vbNewline  ' Get the sub-matched parts of the address.  retStr = retStr & "Email alias is: " & oMatch.SubMatches(0)  ' dragon  retStr = retStr & vbNewline  retStr = retStr & "Organization is: " & oMatch. SubMatches(1)' xyzzy  SubMatchTest = retStrEnd FunctionMsgBox(SubMatchTest("Please send mail to dragon@xyzzy.com. Thanks!"))
 
---------------------------------------------------------------------------------------

The following code is for Regular expression illustrates the use of the Pattern property.

Function RegExpTest(patrn, strng)   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.      RetStr = RetStr & "Match found at position "      RetStr = RetStr & Match.FirstIndex & ". Match Value is '"      RetStr = RetStr & Match.Value & "'." & vbCRLF   Next   RegExpTest = RetStrEnd FunctionMsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions