LeetCode算法题整理(正则篇)regex

193. Valid Phone Numbers

使用bash命令在一行中提取一个文本中的手机号。原题

1
2
3
4
5
6
7
8
9
10
(xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit).
Assume that file.txt has the following content:

987-123-4567
123 456 7890
(123) 456-7890
Your script should output the following valid phone numbers:

987-123-4567
(123) 456-7890
1
awk '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/' telephone.txt