Set regEx = new RegExp
regEx.Pattern = "^[^\d\(]*(\(\d\d\d\)|\d\d\d) (\d\d\d)[- ](\d\d\d\d)(\D|$)"
regEx.Global = True
phonesBlob = WScript.Stdin.ReadAll()
phones = Split(phonesBlob, Chr(10))
N = WScript.Arguments(0)
If N < 1 Then N = 1
While N > 0
For Each line in phones
Set Matches = regEx.Execute(line)
If Matches.Count > 0 Then
' WSCript.Echo "[" & Matches.Count & "]" & line
tel1 = Matches(0).Submatches(0)
If Left(tel1, 1) = "(" Then
tel1 = Mid(tel1, 2, Len(tel1)-2)
End If
tel2 = Matches(0).Submatches(1)
tel3 = Matches(0).Submatches(2)
num = "(" & tel1 & ") " & tel2 & "-" & tel3
If N = 1 Then
Count = Count + 1
WScript.Echo Count & ": " & num
End If
Else
' WScript.Echo "nomatch: " & line
End If
Next
N = N - 1
Wend