I have a snippet of code here which sets up a regular expression for the format you have specified and searches the string, then providing a msgbox
for each instance it finds.
You need to ensure that you have added (using Tools->References) the Microsoft VBScript Regular Expressions 5.5
reference, or you will fail to create the RegExp
object initially.
The regex pattern in this case is specified to allow a bracket (escaped with a \
since otherwise it has special meaning in a regular expression), then two digits, each of which can be 0-9, a close bracket (escaped again), \s
to indicate a space, followed by 4 digits in the character set 0-9, a dash (escaped again) and the final four digits in the 0-9 set.
Don't forget to set the regex Global attribute to True so that it returns all matches.
sString = "Acreaves Alimentos. Rodovia Do Pacifico, (68) 3546-4754 Br 317, Km 8, S/N - Zona Rura... Brasileia - AC | CEP: 69932-000. (68) 3546-5544 . Enviar"
Dim oReg : Set oReg = New RegExp
oReg.Global = True
oReg.Pattern = "\([0-9]{2}\)\s[0-9]{4}\-[0-9]{4}"
Set Matches = oReg.Execute(sString)
For Each oMatch In Matches
MsgBox oMatch.Value
Next
Should do what you require, based on your details and the string you provided.