Not sure if I completely understand the objective, but maybe something like this:
Sub test()
Dim RegExp As Object
Dim s(5) As String, i As Long
Const sPattern As String = "[^0-9]"
s(0) = "F 1."
s(1) = "F 001."
s(2) = "676."
s(3) = "1."
s(4) = "14."
s(5) = "J 12."
Set RegExp = CreateObject("vbscript.regexp")
With RegExp
.Pattern = sPattern
.Global = True
For i = 0 To UBound(s)
If s(i) Like "*#*" Then
Debug.Print .Replace(s(i), "")
End If
Next i
End With
End Sub
Note: No reference is necessary for this code.
--
KL
[MVP - Microsoft Excel]
RU:
http://www.mvps.ru/Program/Default.aspx
ES:
http://mvp.support.microsoft.com/?LN=es-es
EN:
http://mvp.support.microsoft.com/?LN=en-us
Profile:
https://mvp.support.microsoft.com/pr...A-9E6C73C09A36
wrote in message oups.com...
Thank you both for your help.
I went through all of the data tyhat I have to use, and this is the
patter
A ###.
i.e. an optional Alpha Character followed by a space. They always
come together, or are absent together. Then up to 3 numeric
characters then a period.
Examples would be
F 1.
F 001.
676.
1.
14.
J 12.
Ron example works nicely and does what I need, however could you tell
me how to expand on your sPatter to deal with the examples I used
above? I've never worked with this type of matching before, so I'm
not sure how to change the pattern your showed me.
Thanks
b
Sub test()
Dim s(3) As String
Dim i As Long
s(0) = "abc12.xy"
s(1) = "123.abc"
s(2) = "12ab456.xyz"
s(3) = "12345." 'not sure what you want here
Dim oRegex As RegExp
Dim oMatch As Match
Dim colmatches As MatchCollection
Const sPattern As String = "\d{1,3}(?=\.)"
Set oRegex = New RegExp
oRegex.Pattern = sPattern
oRegex.Global = True
For i = 0 To UBound(s)
If oRegex.test(s(i)) = True Then
Set colmatches = oRegex.Execute(s(i))
Debug.Print colmatches(0)
End If
Next i
End Sub
==============================
--ron- Hide quoted text -
- Show quoted text -