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!
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