0

I am trying to match an IPv6 address with square brackets but I am surprisingly stuck...

Works:

echo 'files ([2001:450:671d:200::121]:59464).' | egrep 'files \(.+\)\.$'

Does NOT match (but I think a dot in a character class is valid):

echo 'files ([2001:450:671d:200::121]:59464).' | egrep 'files \([.]+\)\.$'

Any other attempt such as

echo 'files ([2001:450:671d:200::121]:59464).' | egrep 'files \([][0-9:]+\)\.$'
echo 'files ([2001:450:671d:200::121]:59464).' | egrep 'files \([[]0-9:]+\)\.$'
echo 'files ([2001:450:671d:200::121]:59464).' | egrep 'files \([]0-9:[]+\)\.$'
echo 'files ([2001:450:671d:200::121]:59464).' | egrep 'files \([\[\]0-9:]+\)\.$'

Does not work either...

What the heck is wrong here?

1

1 Answer 1

1

That first one, \([.]+\), would match literal dots inside literal parenthesis, like (...) etc. The other ones don't match the hex digits above 9, i.e. abcdef. There's a d in 671d. Remember that IPv6 addresses are in hex.

You'd need to add those, so:

echo 'files ([2001:450:671d:200::121]:59464).' | egrep 'files \([][0-9a-f:]+\)\.$'

or more strictly:

echo 'files ([2001:450:671d:200::121]:59464).' | egrep 'files \(\[[0-9a-f:]+\]:[0-9]+\)\.$'

or use a-fA-F within the brackets if you need to deal with uppercase hex digits too.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .