mirror of
https://github.com/techarkit/shell-scripting-tutorial.git
synced 2025-07-31 05:06:13 +00:00
Add regex example
This commit is contained in:
40
regex.sh
Executable file
40
regex.sh
Executable 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
|
||||
|
Reference in New Issue
Block a user