"Lyle Fairfield" <lylefairfield@aim.comwrote in message
<1153131907.198144.188290@m73g2000cwd.googlegroups .com>:
Quote:
The function posted previously did not handle "666666abc..."
correctly. This is a revision with notes:
>
Public Function SixDigitNumerals(ByVal vInput As String) As Variant
>
' creates pointers to objects
Dim RE As Object
Dim RE2 As Object
>
' creates pointers to objects
Dim SDNMatches As Object
Dim SDNMatches2 As Object
>
' creates a pointer to a variant
Dim SDN As Variant
>
' creates a pointer to a string
Dim SDNS As String
>
' references the VBScript Library
' reserves space in memory
' for twp VBScript Regular Expression Objects
' adn their objects and properties
' and loads default values
Set RE = CreateObject("VBScript.RegExp")
Set RE2 = CreateObject("VBScript.RegExp")
>
' establishes the pattern
' which Regular Expression 2 will attempt to match
' this pattern is
' 6 digits
RE2.Pattern = "\d{6}"
>
With RE
' sets the Global Property
' of Regular Expression 1 to True
' thus directing that all searches and matches
' will find all matching patterns
' rather than just the first one
.Global = True
>
' establishes the pattern
' which the Regular Expression will attempt to match
' this pattern is
>
' (\^|\D) -begin at a input beginning
' or a non-digit character
>
' \d{6} -six digits
>
' (\D|\b) -end at a non-digit character
' or at input end
.Pattern = "(^|\D)\d{6}(\D|$)"
End With
>
' performs a search, matching
' in vInput for the pattern
' established above
' storing results in SDNMatches
' a collection like object
Set SDNMatches = RE.Execute(vInput)
>
For Each SDN In SDNMatches
' performs a search
' on each of the matches found
' matching just the 6 digits
Set SDNMatches2 = RE2.Execute(SDN)
>
' adds a comma
' and the 6 digit substring
' to our working string
SDNS = SDNS & "," & SDNMatches2(0)
Next SDN
>
' removes the first comma from the working string
SDNS = Replace(SDNS, ",", "", , 1)
>
' splits SDNS into a variant array
' of all 6 digit numerals in vInput
' and assigns the array to the function
' as its value
' (returns the array)
SixDigitNumerals = Split(SDNS, ",")
End Function
I've taken the liberty of doing a small alteration of the pattern -
grouping, then doing some alterations of the function, utilizing the
submatches collection of the match object (watch for linebreaks).
http://msdn.microsoft.com/library/de...0e7e82faa5.asp
Function rvsSixDigits(ByVal v_strIn As String) As Variant
Dim re As Object
Dim SDNMatches As Object
Dim SDN As Object
Dim SDNS As String
Set re = CreateObject("vbscript.regexp")
With re
.Global = True
.Pattern = "(^|\D)(\d{6})(\D|$)"
Set SDNMatches = .Execute(v_strIn)
For Each SDN In SDNMatches
SDNS = SDNS & "," & SDN.SubMatches(1)
Next SDN
SDNS = Replace(SDNS, ",", "", , 1)
End With
rvsSixDigits = Split(SDNS, ",")
End Function
--
Roy-Vidar