Test Regular Expression Against A String

In BASH we can perform regular expression on a string using =~ operator, example is given below -

Usage

[[ "string" =~ pattern ]]

Example

$ if [[ "Hello" =~ "1" ]]; then echo "True"; else echo "False"; fi
False

Source: Unix - StackExchange

Last updated