Kartik Deshpande Kartik Deshpande - 4 months ago 12
Bash Question

add a special symbol to character class alnum

Can i add something to a character class ?

like we know

[:alnum:]


contains all alpha numeric characters !!

So i want to add a special symbol (.) dot to the class !!
How can we do it?

I tried this,

class='\.*[:alnum:]'
newclass="[$class]"


storing a class alnum and dot into a variable string newclass and after that using $newclass in awk but no luck

Answer

You can include any character like:

[.[:alnum:]]

Testing this in a BASH regex:

[[ 'abc.123' =~ ^[.[:alnum:]]+$ ]] && echo "ok" || echo "no"
ok

[[ 'abc.123' =~ ^[[:alnum:]]+$ ]] && echo "ok" || echo "no"
no