Can you solve this real interview question? Valid Phone Numbers - Given a text file file.txt that contains a list of phone numbers (one per line), write a one-liner bash script to print all valid phone numbers. You may assume that a valid phone number m
Given a text filefile.txtthat contains list of phone numbers (one per line), write a one liner bash script to print all valid phone numbers. You may assume that a valid phone number must appear in one of the following two formats: (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit...
leetcodePython【193】: Valid Phone Numbers https://leetcode.com/problems/valid-phone-numbers/description/ 使用grep -P是POSIX正则规范。 \d是非常规正则 grep-P"^(\\d{3}-|\\(\\d{3}\\) )\\d{3}-\\d{4}$"file.txt 所以,如果用grep -E 或者 egrep的时候,如下: grep -E "^([0-9]{...
Given a text filefile.txtthat contains list of phone numbers (one per line), write a one liner bash script to print all valid phone numbers. You may assume that a valid phone number must appear in one of the following two formats: (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit...
https://leetcode.com/problems/valid-phone-numbers/description/ Shell脚本题目:给file.txt ,输出复合格式的电话号码。思路是使用正则,但是有几个坑。 注意grep -E 与grep -P 的区别 https://www.jianshu.com/p/e1acfb7989b2 -E 其实是扩展支持|与& 这种方式,-P才是Perl正则 ...
https://alid-phone-numbers/ leetcode.com/problems/valid-phone-numbers/discuss/55481/Three-different-solutions-using-grep-sed-and-awk 该文章遵循创作共用版权协议 CC BY-NC 4.0,要求署名、非商业 、保持一致。在满足创作共用版权协议 CC BY-NC 4.0的基础上可以转载,但请以超链接形式注明出处。文章仅代表作...
Valid Phone Numbers,#Readfromthefilefile.txtandoutputallvalidphonenumberstostdout.awk'/^([0-9]{3}-|\([0-9]{3}\))[0-9]{3}-[0-9]{4}$/{print$0}'file.txt
Your script should output the following valid phone numbers: 987-123-4567 (123) 456-7890 1. 2. 解题思路 模式伪代码如下: ((数字数字数字-)|(\(数字数字数字\) ))(数字数字数字)-(数字数字数字数字) 1. AC 代码 # 1. ^ 表示需要在行的开始处进行匹配. 例如, ^abc 可以匹配 abc123 但不匹配 ...
aCathie Cathie[translate] aA valid phone number is required. If you have already entered a number, please make sure that there are no dashes, periods, or spaces separating the numbers (for example, 5551234567). 正在翻译,请等待... [translate]...