Link to home
Start Free TrialLog in
Avatar of azcalv408
azcalv408

asked on

matching regular expression help

hello,
   can someone help figure out what's wrong with these statements? I'm trying to compare correct format of phone numbers and it seems to not detecting the "-"

set phnum = ""
set test = 0
while ($test == 0)
        if("$phonenum" =~ [0-9][0-9][0-9][-][0-9][0-9][0-9][-][0-9][0-9][0-9][0-9]) then
                  break
          else
                 echo "Need to enter phone number in correct forma pleaset"
                   set phonenum = "$<"
         endif
end
Avatar of ozo
ozo
Flag of United States of America image

=~ in csh is not a regular expression it is a file glob, but your code seems to work if I change phnum to phonenum
Avatar of azcalv408
azcalv408

ASKER

sorry my mistake, suppose to be  
set phonenum = ""

it doesn't work, it keeps going into the else part even if i enter 333-333-3333

but then if i put 3333333333 ,  it matches it
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
brackets around the - are completely unecessary, but in my csh it globs exactly the same thing with or without them