diff --git a/regex.sh b/regex.sh new file mode 100755 index 0000000..62f2445 --- /dev/null +++ b/regex.sh @@ -0,0 +1,40 @@ +#!/bin/bash +#Purpose: regex examples +#Version:1.0 +#Create Date: +#Modified Date: + +# START # + +numString1="1234" +numString2="16789" +numString3="1579" + + +echo "Example 1" +if [[ $numString1 =~ ^1 ]]; then + echo "String \"$numString1\" starts with a \"1\", and matches regex: ^1" +fi + +echo "Example 2" +if [[ $numString2 =~ ^1 ]]; then + echo "String \"$numString2\" starts with a \"1\", and matches regex: ^1" +fi + +echo "Example 3" +if [[ $numString3 =~ ^1.7 ]]; then + echo "String \"$numString2\" starts with a \"1\", followed by any character, and followed by a 7. " + echo "This string matches the regex: ^1.7" +fi + +echo "Example 4" +if [[ ! $numString1 =~ ^1.7 ]]; then + echo "String \"$numString1\" does not start with a \"1\", followed by any character, and followed by a 7. " + echo "This string does not match the regex: ^1.7" +fi + +echo "Example 5" +if [[ $numString2 =~ 9$ ]]; then + echo "String \"$numString2\" ends with a \"9\", and matches the regex: 9$" +fi +