Add regex example

This commit is contained in:
Jessica Lee
2022-11-27 02:20:15 -05:00
parent 68f15e7704
commit d8d9a82c7d

40
regex.sh Executable file
View File

@ -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