You are given a text file. Write a script to display all valid phone numbers in the given text file.
Acceptable Phone Number Formats+nn nnnnnnnnnn
(nn) nnnnnnnnnn
nnnn nnnnnnnnnn
Input File
0044 1148820341
+44 1148820341
44-11-4882-0341
(44) 1148820341
00 1148820341
Output
0044 1148820341
+44 1148820341
(44) 1148820341
處理的程式:
set infile [open "input.dat" r]
while { [gets $infile line] >= 0 } {
set data [string trim $line]
if {[regexp {(^\+\d{2}|^\(\d{2}\)|^\d{4})\s\d{10}$} $data]} {
puts $line
}
}
close $infile
沒有留言:
張貼留言