Skip to content

Commit 7f089cb

Browse files
authored
Merge pull request techarkit#9 from jlee882/FOTV
Regex shell scripting tutorial
2 parents 68f15e7 + 332cb67 commit 7f089cb

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

regex.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
#Purpose: regex examples
3+
#Version: 1.0
4+
#Create Date: Sun Nov 27 00:27:33 EST 2022
5+
#Modified Date:
6+
7+
# START #
8+
9+
numString1="1234"
10+
numString2="16789"
11+
numString3="1579"
12+
13+
14+
echo "Example 1"
15+
if [[ $numString1 =~ ^1 ]]; then
16+
echo "String \"$numString1\" starts with a \"1\", and matches regex: ^1"
17+
fi
18+
19+
echo "Example 2"
20+
if [[ $numString2 =~ ^1 ]]; then
21+
echo "String \"$numString2\" starts with a \"1\", and matches regex: ^1"
22+
fi
23+
24+
echo "Example 3"
25+
if [[ $numString3 =~ ^1.7 ]]; then
26+
echo "String \"$numString2\" starts with a \"1\", followed by any character, and followed by a 7. "
27+
echo "This string matches the regex: ^1.7"
28+
fi
29+
30+
echo "Example 4"
31+
if [[ ! $numString1 =~ ^1.7 ]]; then
32+
echo "String \"$numString1\" does not start with a \"1\", followed by any character, and followed by a 7. "
33+
echo "This string does not match the regex: ^1.7"
34+
fi
35+
36+
echo "Example 5"
37+
if [[ $numString2 =~ 9$ ]]; then
38+
echo "String \"$numString2\" ends with a \"9\", and matches the regex: 9$"
39+
fi
40+

0 commit comments

Comments
 (0)