Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

regex

grep

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

I've been trying these two regexes with egrep in some texts and they seem to be equivalent. Is there a case they won't be return same results?

Also, in the second expression, what is the meaning of the second - and why would I need it? I am bit confused with these simple examples.

like image 482
nacho4d Avatar asked Nov 28 '22 17:11

nacho4d


1 Answers

The second expression also matches a dash as well as hexadecimals

Edit in egrep, which is what you're using the second one is in fact invalid:

# echo "12345678" | egrep '^[0-9a-f-A-F]+$'
egrep: Invalid range end

The correct expression for the second is by ending with a dash:

[0-9a-fA-F-]
like image 99
Ja͢ck Avatar answered Dec 04 '22 05:12

Ja͢ck