From 8d2055483e8c0a8147414f4695a7cf3e5ede819e Mon Sep 17 00:00:00 2001 From: Martin Nicholson Date: Tue, 16 Jan 2018 16:03:13 +0000 Subject: [PATCH] Added section for =~ operator --- bash.html.markdown | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bash.html.markdown b/bash.html.markdown index fa3c5ebe..354042ec 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -161,6 +161,16 @@ then echo "This will run if $Name is Daniya OR Zach." fi +# There is also the =~ operator, which tests a string against a Regex pattern: +Email=me@example.com +if [[ "$Email" =~ [a-z]+@[a-z]{2,}\.(com|net|org) ]] +then + echo "Valid email!" +fi +# Note that =~ only works within double [[ ]] square brackets, +# which are subtly different from single [ ]. +# See the appropriate [manual section](http://www.gnu.org/software/bash/manual/bashref.html#Conditional-Constructs) for more on this. + # Expressions are denoted with the following format: echo $(( 10 + 5 )) # => 15