I am trying to extract a phone number from a text string,
display the first part of string before the phone number, then the second part, then the phone number.
I am first splitting the the string:
then am looping to find a match and capturing the array index:
then I am looping twice to rebuild the strings:
[/i]
then am displaying:
It is ugly but it works except that I am not able to get the syntax for the regular expression to match the pattern 123-123-1234 or 123 123 1234(spaces)
I have tried several variatons of somethign like:
"\d{3}(-|\s)\d{3}(-|\s)\d{4}", but can't get it.
If someone could help with the regex it would be greatly appreciated and a great Kharma builder
display the first part of string before the phone number, then the second part, then the phone number.
I am first splitting the the string:
Code:
[i]
text = cstr(rsAd("adtext"))
aryTxt = split(text," ")
[/i]
Code:
[i]
Set regex = New regExp
regex.Pattern = "\d{3}-\d{3}-\d{4}"
for x=0 to ubound(aryTxt)
if regex.Test(aryTxt(x)) then
phn = x
end if
next
[/i]
Code:
[i]
FrstStr = ""'build string prior to phone #
for y=0 to phn - 1
FrstStr = Frststr & aryTxt(y) & " "
next
SecStr = ""'build string after phone #
for z=phn + 1 to ubound(arytxt)
SecStr = SecStr & arytxt(z)& " "
next
then am displaying:
Code:
[i]
Frststr & " " & secStr & " " & aryTxt(phn)
[/i]
It is ugly but it works except that I am not able to get the syntax for the regular expression to match the pattern 123-123-1234 or 123 123 1234(spaces)
I have tried several variatons of somethign like:
"\d{3}(-|\s)\d{3}(-|\s)\d{4}", but can't get it.
If someone could help with the regex it would be greatly appreciated and a great Kharma builder