forked from itamarg365/linuxjourney
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathregular-expressions-regex.html
More file actions
184 lines (155 loc) · 5.92 KB
/
Copy pathregular-expressions-regex.html
File metadata and controls
184 lines (155 loc) · 5.92 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>regular-expressions-regex</title>
<script
src="../static/assets/category/application-8013fdc35e4c79f95bcb3d655ff61f137ac05bcee52e6d96588427a84eddef12.js.download"
data-turbolinks-track="true"></script>
<link rel="stylesheet" media="all"
href="../static/assets/category/application-b0b91461d093aa2ed95d8a7467856e4dc16f55744d3c17a927c3598e5b26cd3f.css"
data-turbolinks-track="true">
</head>
<body>
<div id="wrapper" class="active">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul id="sidebar_menu" class="sidebar-nav">
<li class="sidebar-brand"><a>Text Fu Advanced</a>
</li>
</ul>
<ul class="sidebar-nav" id="sidebar">
<li>
<a class="current" href="regular-expressions-regex.html">
1. Regular expressions regex</a>
</li>
<li>
<a class="" href="text-editors-vim-or-emacs.html">
2. Text editors vim or emacs</a>
</li>
<li>
<a class="" href="vim-text-editor.html">
3. Vim text editor</a>
</li>
<li>
<a class="" href="vim-search-patterns.html">
4. Vim search patterns</a>
</li>
<li>
<a class="" href="vim-navigation.html">
5. Vim navigation</a>
</li>
<li>
<a class="" href="vim-inserting-appending-text.html">
6. Vim inserting appending text</a>
</li>
<li>
<a class="" href="vim-editing.html">
7. Vim editing</a>
</li>
<li>
<a class="" href="vim-saving-and-exiting.html">
8. Vim saving and exiting</a>
</li>
<li>
<a class="" href="emacs-text-editor.html">
9. Emacs text editor</a>
</li>
<li>
<a class="" href="emacs-manipulate-files.html">
10. Emacs manipulate files</a>
</li>
<li>
<a class="" href="emacs-buffer-navigation.html">
11. Emacs buffer navigation</a>
</li>
<li>
<a class="" href="emacs-editing.html">
12. Emacs editing</a>
</li>
<li>
<a class="" href="emacs-exiting-and-help.html">
13. Emacs exiting and help</a>
</li>
</ul>
</div>
<!-- End of Sidebar -->
<div id="page-content-wrapper">
<!-- Keep all page content within the page-content inset div! -->
<div class="page-content inset">
<div class="row">
<div class="col-md-6 lesson">
<div class="user-app">
<a class="btn btn-default btn-sm" href="../index.html">
Home
</a>
</div>
<div class="lesson-content">
<h3>regex (Regular Expressions)</h3>
<p>Regular expressions are a powerful tool to do pattern based selection. It uses special notations similar to those we've encountered already such as the * wildcard. </p>
<p>We'll go through a couple of the most common regular expressions, these are almost universal with any programming language.</p>
<p>Well use this phrase as our test string:<br/>
<pre><br/>
sally sells seashells <br/>
by the seashore<br/>
</pre></p>
<p><b>1. Beginning of a line with ^</b></p>
<pre>
<b>^</b>by
would match the line "by the seashore"
</pre>
<p><b>2. End of a line with $</b></p>
<pre>
seashore<b>$</b>
would match the line "by the seashore"
</pre>
<p><b>3. Matching any single character with .</b></p>
<pre>
b<b>.</b>
would match by
</pre>
<p><b>4. Bracket notation with [] and ()</b></p>
<p>This can be a little tricky, brackets allow us to specify characters found within the bracket. </p>
<pre>
d<b>[iou]</b>g
would match: dig, dog, dug
</pre>
<p>The previous anchor tag ^ when used in a bracket means anything except the characters within the bracket. </p>
<pre>
d<b>[^i]</b>g
would match: dog and dug but not dig
</pre>
<p>Brackets can also use ranges to increase the amount of characters you want to use. </p>
<pre>
d<b>[a-c]</b>g
will match patterns like dag, dbg, and dcg
</pre>
<p>Be careful though as brackets are case sensitive:</p>
<pre>
d<b>[A-C]</b>g
will match dAg, dBg and dCg but not dag, dbg and dcg
</pre>
<p>And those are some basic regular expressions.</p>
</div>
</div>
<div class="col-md-6 practice">
<div class="exercise-content">
<h3>Exercise</h3>
<p>Try to combine regular expressions with grep and search through some files.</p>
<pre>
grep [regular expression here] [file]
</pre>
</div>
<div class="quiz-content">
<h3>Quiz Question</h3>
<p>What regular expression would you use to match a single character?</p>
<h3>Quiz Answer</h3>
<p>.</p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>