Why isn't this regular expression test working?

<>

This question already has an answer here:

Answers


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


Try

if [[ $line =~ [a-zA-Z]+\. ]] ; then echo hello; fi

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


Need Your Help

Guice best practices and anti-patterns

java dependency-injection design-patterns guice

I'm not sure if there is merit to this question or not, but are there any best practices and anti-patterns specific to Google Guice?

Jquery .on() submit event

jquery ajax forms submit

I've got a problem with .on().