Leetcode 193.Valid Phone Numbers
Shell腳本題目:給file.txt ,輸出復合格式的電話號碼。思路是使用正則,但是有幾個坑。
-
註意grep -E 與grep -P 的區別 https://www.jianshu.com/p/e1acfb7989b2
-E 其實是擴展支持| 與& 這種方式,-P才是Perl正則 - 註意正則使用^ 和 $ 包圍精確匹配
- 剛開始使用cat 和read 讀取文件,發現要麽多個空格省略成一個,要麽修改IFS為‘‘ 但是又處理不了換行。https://stackoverflow.com/questions/7314044/use-bash-to-read-line-by-line-and-keep-space
grep -P "^(\d{3}-|\(\d{3}\) )\d{3}-\d{4}$" file.txt
Leetcode 193.Valid Phone Numbers
相關推薦
Leetcode 193.Valid Phone Numbers
ID ace 精確匹配 esc stack pre .com 區別 numbers https://leetcode.com/problems/valid-phone-numbers/description/Shell腳本題目:給file.txt ,輸出復合格式的電話號碼。
LeetCode 193. Valid Phone Numbers
分析 難度 易 來源 https://leetcode.com/problems/valid-phone-numbers/ 題目 Given a text file file.txt that contains list of phone numbers (one per line), write
LeetCode(193. Valid Phone Numbers)(sed用法)
hat 數據文件 工具 version flags png digi lac inpu 193. Valid Phone Numbers Given a text file file.txt that contains list of phone n
193. Valid Phone Numbers bash正則
描述 輸入 987-123-4567 123 456 7890 (123) 456-7890 輸出 987-123-4567 (123) 456-7890 正則匹配過濾。 grep
193. Valid Phone Numbers#1
題目摘要 從檔案裡篩選出電話號碼,電話號碼有兩種格式 (xxx) xxx-xxxx 和 xxx-xxx-xxxx。假設每行頭尾都沒有空格。 解法 注意 可問問題 原題 Given a text file file.txt that contains
[LeetCode] Valid Phone Numbers 驗證電話號碼
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bash script to print all valid phone numbers. You may a
[Bash]LeetCode193. 有效電話號碼 | Valid Phone Numbers
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bash script to print all valid phone numbers. Y
LeetCode Valid Phone Number
Problem Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bash script to pr
leetcode--Python正則表示式解析Valid Phone nums
#!/usr/bin/env python import os import re import sys filename=sys.argv[1] fd=open(filename,"r") inde
[leetcode-593-Valid Square]
osi poi 相等 code int art tab gre span Given the coordinates of four points in 2D space, return whether the four points could construct a
[LeetCode] 448.Find All Numbers Disappeared in an Array
return htm put lis inpu pear rand ati n) p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #4e9072 } p.p2 { margin: 0.0
LeetCode - 2 - Add Two Numbers
dtw ble bind ber plus binding bsp pan number 題目 URL:https://leetcode.com/problems/add-two-numbers/ 解法 沒什麽特殊的解法,按位相加即可。 註意點: 1、l1 和 l
[leetcode-611-Valid Triangle Number]
example targe n-n ans gles clas hat bin length Given an array consists of non-negative integers, your task is to count the number of trip
LeetCode 2: Add Two Numbers
ret change add cal lis || div span style Tips: Tried to use a private method to simplize the code. But found that object is passed by ref
Timus : 1002. Phone Numbers 題解
targe sta hone cin 組合 name emp clas keys 把電話號碼轉換成為詞典中能夠記憶的的單詞的組合,找到最短的組合。 我這道題應用到的知識點: 1 Trie數據結構 2 map的應用 3 動態規劃法Word Break的
leetcode--(36. Valid Sudoku)
描述 blog board 3*3 urn oar leetcode true clas 描述:9*9的方格,每一行每一列必須是1~9,每一個單元的3*3方格必須是1~9 func isValidSudoku(board [][]byte) bool { //定義3個二維
LeetCode 98: Valid Binary Search Tree
div pub tree lee ret node eno cnblogs logs This answer is so awesome!! /** * Definition for a binary tree node. * public class TreeN
leetcode: Longest Valid Parentheses分析和實現
fin 最大 區間 之間 n) parent 復雜度 gif package 題目大意:給出一個只包含字符‘(‘和‘)‘的字符串S,求最長有效括號序列的長度。 很有趣的題目,有助於我們對這種人類自身制定的規則的深入理解,可能我們大多數人都從沒有真正理解過怎樣
LeetCode - 2. Add Two Numbers
ont and contain nod emp list sts init pre You are given two non-empty linked lists representing two non-negative integers. The digits are
[leetcode] 2. Add Two Numbers
code eve ini emp any n-n self 申請 tno You are given two non-empty linked lists representing two non-negative integers. The digits are stor