forked from GGC-SD/bash_basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregex.sh
More file actions
39 lines (22 loc) · 672 Bytes
/
regex.sh
File metadata and controls
39 lines (22 loc) · 672 Bytes
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
# using regex in Unix as it applies to tools like sed or grep (egrep)
# characters
[a-z] mataches a to z
. matches any character
# character classes
/c.t/ matches 'cat', 'cbt', and 'czt'
/c[ab]t/ matches 'cat' and 'cbt'
/c[a-k]t/ matches 'cat' and 'cft'
/c[^a-k]t/ matches 'cmt' and 'czt' but not 'cat'
# repetitions
/dog*/ matches 'do', 'dog', 'dogg'
/dog+/ matches 'dog', 'dogg'
/dog?/ matches 'do' or 'dog'
/dog{3,5}/ matches 'doggg' 'dogggg' 'doggggg'
# Grouping & Anchor Points
/(dog)*/ matches 'dog' , 'dogdog'
/th(is|at)/ matches 'this' or 'that'
^ beginning of a string
$ end of a string
\b word boundary
\w word character
\s whitespace character