Can anyone help me understand why this doesn't work? Just trying out some simple regex in bash.
#!/bin/bash
re="-regex_"
if [[ "$re" =~ ^[-[:alpha:]_]+$ ]]; then
echo "Regex"
else
echo "this is not regex"
fi
Cheers
Can anyone help me understand why this doesn't work? Just trying out some simple regex in bash.
#!/bin/bash
re="-regex_"
if [[ "$re" =~ ^[-[:alpha:]_]+$ ]]; then
echo "Regex"
else
echo "this is not regex"
fi
Cheers
I am assuming that you are hoping that the "-regex_" will evaluate to true in your if statement.
on the [:alpha:] tag there is nothing to say search for more than one alpha-numeric character.
try
[[ "$re" =~ ^-[[:alpha:]]+_$ ]]