Hi all,
Using Excel 2010, 2013.
What would be the correct regular expression pattern to extract this substring : 234-456-00000000-45-234 from a string like
mnasdf 234 234-456-00000000-45-234 sdf 123 34
The string will vary, the substring does not vary other than the digits can be any number 0-9
I need to retain the hyphens "-" as well
I tried patterns like
.Pattern = "[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9]"
.Pattern = "/d{3}-/d{3}-/d{8}-/d{2}-/d{3}"
But not working
Thx
w
Sub Test()
Const strTest As String = "234-456-00000000-45-234"
Debug.Print RE6(strTest)
End Sub
Function RE6(strData As String) As String
Dim RE As Object, REMatches As Object
Set RE = CreateObject("vbscript.regexp")
With RE
.MultiLine = False
.Global = False
.IgnoreCase = True
.Pattern = "[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9]"
End With
Set REMatches = RE.Execute(strData)
RE6 = REMatches(0)
End Function
Bookmarks