-
Notifications
You must be signed in to change notification settings - Fork 613
/
Copy pathregex.sh
executable file
·40 lines (31 loc) · 1019 Bytes
/
regex.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
#Purpose: regex examples
#Version: 1.0
#Create Date: Sun Nov 27 00:27:33 EST 2022
#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