Matching using Test Method 1

Send Snippet To: Save this snippet to Code Collector Pro -- view all surfrgeek's snippets
language: Other
license: Other

Code for Snippet:

                
Option Explicit
 
'********************************************
'MATCHING ONLY Examples using the TEST method
'********************************************
 
Public Sub Matching_1()
    'declare a RegExp type
    Dim Reg As RegExp
 
    'declare other variables
    Dim str As String
    Dim valid As Boolean
 
    'create a new RegExp object
    Set Reg = New RegExp
 
    'set string to be tested
    str = "P1234 "
 
    'set the desired pattern in the RegExp object
    Reg.Pattern = "P\d\d\d\d$"
 
    'conduct testing
    valid = Reg.Test(str)   'Use Test method of the object
 
    MsgBox valid
 
End Sub
'==========================================================================
 
Public Sub Matching_2()
    'declare a RegExp type
    Dim Reg As RegExp
 
    'declare other variables
    Dim str As String
    Dim valid As Boolean
 
    'create a new RegExp object
    Set Reg = New RegExp
 
    'set string to be tested
    str = "(809)224-1234"
 
    'set the desired pattern in the RegExp object
    Reg.Pattern = "^\(\d\d\d\)\d\d\d\-\d\d\d\d$"
 
    'conduct testing
    valid = Reg.Test(str)  'Use Test method of the object
 
    MsgBox valid
 
End Sub
 
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 22
Date Added: 2017-09-09 19:05:43
Last Modified: 2017-09-09 14:05:58

Web Analytics