CORRECTED POST
@stribizhev is right. You cannot use look-aheads in bash regex. I used grep for that.
#!/bin/bash
fqdn=$1
result=`echo $fqdn | grep -P '(?=^.{1,254}$)(^(?>(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)'`
if [[ -z "$result" ]]
then
echo "$fqdn is NOT a FQDN"
else
echo "$fqdn is a FQDN"
fi
exit
Thanks to the help of @stribizhev and < +OnlineCop > and < tureba > at http://webchat.freenode.net/?nick=regex101 .
ORIGINAL POST
I am trying to make this regex work to evaluate if the string is or not a valid FQDN with no success. I went through various searches with no success too.
For example, I copied a regex find at http://regexlib.com/REDetails.aspx?regexp_id=1319 and tried this way but is not working. What can be wrong?
#!/bin/bash
fqdn=$1
if [[ "$fqdn" =~ (?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$) ]]
then
echo "$fqdn is a FQDN"
else
echo "$fqdn is NOT a FQDN"
fi
exit