[0-9a-fA-F] is the same as [0-9a-fAF]?

Are these two equivalents? [0-9a-fA-F]and[0-9a-f-A-F]

I am trying to use these two regular expressions with egrep in some texts and they seem to be equivalent. Is there a case that they do not return the same results?

Also, in the second expression, what is the meaning of the second -and why do I need it? I am a little confused by these simple examples.

+3
source share
3 answers

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-]
+9
source

, . '-'

+7

[0-9a-f-A-F]= [0-9a-fA-F] + -

+2

All Articles