shell(二)获取有效电话号码 LeetCode

版权声明:可以转载,请注明链接出处 https://blog.csdn.net/xihuanyuye/article/details/81870981

data.txt文件内容:
cat data.txt
987-123-4567
123 456 7890
(123) 456-7890
shell命令:
sed -n -r ‘/^(?[0-9]{3})?( |-)[0-9]{3}-[0-9]{4}$/p’ data.txt
解释:
-n 设置静默输出,后续/p输出匹配项目
-r 扩展正则表达式规则
-r后的‘‘符号内为具体的正则表达式规则,具体参考相关文献
https://www.cnblogs.com/sherlockhomles/archive/2013/08/01/3229446.html#commentform

猜你喜欢

转载自blog.csdn.net/xihuanyuye/article/details/81870981