Wrong Output of Shell question "valid phone number"


  • 0
    Y

    For Shell Question "valid phone number", I submitted the below code:

     while read LINE
     do
         if [[ $LINE =~ "^\([0-9]{3}\) [0-9]{3}-[0-9]{4}$" ]] || [[ $LINE =~ "^[0-9]{3}-[0-9]{3}-[0-9]{4}$" ]]; then
             echo $LINE
         fi
     done < 'file.txt'
    

    Finally, Leetcode judge my code to wrong output by one input "123-456-7891".
    However, such input can be pass from my own test.

    ytjiang@xxxxx:~/code_practice % sh ValidPhoneNumber.sh
    123-456-7891
    

    Really wired me....

    Thanks in advance!


Log in to reply
 

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