I have this
echo $line
Thisisaline.
I was wondering why is this not working:
if [[ "$line" =~ "[a-zA-Z]+\.$" ]] ; then echo "hello"; fi
Above regex gives no output.
I have this
echo $line
Thisisaline.
I was wondering why is this not working:
if [[ "$line" =~ "[a-zA-Z]+\.$" ]] ; then echo "hello"; fi
Above regex gives no output.
The problem is that you are using quotes...
In bash regex, there is no need for quotes, and moreso, they should not be used (unless you are trying to match a quote (in which case you can escape it \"
)... Also if you want a space in your pattern, you must escape it, \
(there is a space after the back-slash ...
Also note, that to match the entire line as being alphabetic, you must add a leading ^
and a trailing $
, otherwise it will match such lines as: 123 456 abc. cat and mouse
Some version of OS with bash gives you the output. So its up to you to get your updates. However, without regex you can use extended globbing
shopt -s extglob
case "$line" in
+([a-zA-Z]). ) echo "hello";;
esac
if not, use regex without the quotes