File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments