Quick regex question about alphabetic string

Hi guys,

Pretty new to regex, and i know im doing something wrong here. I'm trying to get a regex command that restricts a string to be 8 characters long, and the first character cannot be 0. Here's what i have so far...

echo "01234" | grep "^[0][0-9]{8}*$"

Thanks very much!

-Crawf

EDIT: Sorry about the wrong title, after two long hours of trying another regex command to work, about 30 seconds after posting managed to figure out an answer by myself...Sorry!

no need regular expression. KISS

[[ ${#num} -ne 8 ]] && echo "not equal 8 characters" && exit
case $num in
 0* ) echo "0 as first character""  &&     exit ;;
esac

Aha! That works as well!

Thanks mate!

-Crawf

If you are using ksh93, the following is one way of testing the numeric string is of length 8 and does not have a leading zero

#!/bin/ksh93

num="12345678"
req_len=8

if [[ ${#num}-$num == $req_len-${num/?('0')({7,8}(\d))*/\2} ]]
then
   print "OK - $num matches criteria"
else
   print "Sorry - $num contains either a leading zero or is not of length ${req_len}!"
fi

Can that be done in the Bourne shell? Thats what i'm working in...

Looks just what i need though! Thanks!

-Crawf

$echo "01234567"|awk 'BEGIN{FS=null}{if(length==8 && $1!='0') print"Valid"}'
$echo "91234567"|awk 'BEGIN{FS=null}{if(length==8 && $1!='0') print"Valid"}'
Valid

Thanks Abhishek Ghose! That works well too!

Thanks for the support guys!

-Crawf

case $num in [1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]) echo fine;;
  *) echo not good at all, play again;;
esac