Kartik Deshpande Kartik Deshpande - 1 year ago 67
Bash Question

add a special symbol to character class alnum

Can i add something to a character class ?

like we know


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,


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

Answer Source

You can include any character like:


Testing this in a BASH regex:

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

[[ 'abc.123' =~ ^[[:alnum:]]+$ ]] && echo "ok" || echo "no"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download