Skip to content

Latest commit

 

History

History
24 lines (15 loc) · 429 Bytes

193.md

File metadata and controls

24 lines (15 loc) · 429 Bytes

Valid Phone Numbers

Description

link


Solution

See Code


Code

O(n)

# Read from the file file.txt and output all valid phone numbers to stdout.
grep -P '^(\d{3}-|\(\d{3}\) )\d{3}-\d{4}$' file.txt
# sed -n -r '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/p' file.txt
# awk '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/' file.txt