"Leon" <et**@op.pl> wrote in news:bq**********@news.onet.pl:
Hi!
Do I can obtain submatches in VBA (A2k) using VBS Reg Expr 5.5
reference??
Eg. pattern - "(a-z)*(0-9)*"
$1 - some text
$2 - some number
Thanx for any help!
Leon.
An Example (the news client has inserted line breaks):
Option Explicit
' assumes VBScript is installed
Dim RE As Object
Sub TestAplphaOnly()
Dim StringToBeMasked As String ' string to be masked
Dim MaskPattern As String ' mask note this can be formatted
' as a regular expression pattern
Dim Globally As Boolean ' global search
Dim IgnoreCase As Boolean ' ignore case
StringToBeMasked = "L1Y9L3E7"
MaskPattern = "[^A-Z]" ' Alpha Only
' that is,
' remove all characters except those from A to
Z
Globally = True
IgnoreCase = True
InitializeRegExp MaskPattern, Globally, IgnoreCase
SetMask StringToBeMasked
' to test only
' remove for actual use
MsgBox StringToBeMasked
ReleaseRegExp
End Sub
Public Sub InitializeRegExp( _
ByRef MaskPattern As String, _
Optional ByRef Globally As Boolean = True, _
Optional ByRef IgnoreCase As Boolean = True)
Set RE = CreateObject("VBScript.RegExp") 'late binding ... Dev would
squirm With RE
.Global = Globally
.IgnoreCase = IgnoreCase
.Pattern = MaskPattern
End With
End Sub
Public Sub ReleaseRegExp()
Set RE = Nothing
End Sub
Public Sub SetMask(ByRef StringToBeMasked As String)
StringToBeMasked = RE.Replace(StringToBeMasked, "")
End Sub
--
Lyle
(for e-mail refer to
http://ffdba.com/contacts.htm)