The second expression also matches dashes as well as hexadecimal elements
Change in egrep, that you use the second one is actually invalid:
# echo "12345678" | egrep '^[0-9a-f-A-F]+$'
egrep: Invalid range end
The correct expression for the second ends with a dash:
[0-9a-fA-F-]
source
share