My "grep -E" solution


  • 3
    T
    # Read from the file file.txt and output all valid phone numbers to stdout.
    
    # use grep -P
    grep -P '^\([0-9]{3}\)\s[0-9]{3}-[0-9]{4}$|^[0-9]{3}-[0-9]{3}-[0-9]{4}$' file.txt

  • 0
    P

    grep -P '^((\d{3})\s\d{3}-\d{4}|\d{3}-\d{3}-\d{4})$' file.txt


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.