You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Regular expression is a group of characters or symbols which is used to find a specific pattern from a text.
@@ -19,32 +24,33 @@ contains uppercase letter and also it is too short.
19
24
20
25
## Table of Contents
21
26
22
-
-[Basic Matchers]()
23
-
-[Meta character]()
24
-
-[Full stop]()
25
-
-[Character set]()
26
-
-[Negated character set]()
27
-
-[Repetitions]()
28
-
-[The Star]()
29
-
-[The Plus]()
30
-
-[The Question Mark]()
31
-
-[Character Group]()
32
-
-[Alternation]()
33
-
-[Escaping special character]()
34
-
-[Anchors]()
35
-
-[Caret]()
36
-
-[Dollar]()
37
-
-[Shorthand Character Sets]()
38
-
-[Lookaround]()
39
-
-[Positive Lookahead]()
40
-
-[Negative Lookahead]()
41
-
-[Positive Lookbehind]()
42
-
-[Negative Lookbehind]()
43
-
-[Flags]()
44
-
-[Case Insensitive]()
45
-
-[Global search]()
46
-
-[Multiline]()
47
-
-[Bonus]()
27
+
-[Basic Matchers](#1-basic-matchers)
28
+
-[Meta character](#2-meta-characters)
29
+
-[Full stop](#21-full-stop)
30
+
-[Character set](#22-character-set)
31
+
-[Negated character set](#221-negated-character-set)
32
+
-[Repetitions](#23-repetitions)
33
+
-[The Star](#231-the-star)
34
+
-[The Plus](#232-the-plus)
35
+
-[The Question Mark](#233-the-question-mark)
36
+
-[Braces](#24-braces)
37
+
-[Character Group](#25-character-group)
38
+
-[Alternation](#26-alternation)
39
+
-[Escaping special character](#27-escaping-special-character)
40
+
-[Anchors](#28-anchors)
41
+
-[Caret](#281-caret)
42
+
-[Dollar](#282-dollar)
43
+
-[Shorthand Character Sets](#3-shorthand-character-sets)
44
+
-[Lookaround](#4-ookaround)
45
+
-[Positive Lookahead](#41-positive-lookahead)
46
+
-[Negative Lookahead](#42-negative-lookahead)
47
+
-[Positive Lookbehind](#43-positive-lookbehind)
48
+
-[Negative Lookbehind](#44-negative-lookbehind)
49
+
-[Flags](#5-flags)
50
+
-[Case Insensitive](#51-case-insensitive)
51
+
-[Global search](#52-global-search)
52
+
-[Multiline](#53-multiline)
53
+
-[Bonus](#bonus)
48
54
49
55
## 1. Basic Matchers
50
56
@@ -188,7 +194,7 @@ the comma the regular expression `[0-9]{2}` means: Match exactly 2 digits.
188
194
"[0-9]{2}" => The number was 9.<ahref="#learn-regex"><strong>99</strong></a><ahref="#learn-regex"><strong>97</strong></a> but we rounded it off to <ahref="#learn-regex"><strong>10</strong></a>.0.
189
195
</pre>
190
196
191
-
## 2.4 Character Group
197
+
## 2.5 Character Group
192
198
193
199
Character group is a group of sub-pattern that is written inside Parentheses `(...)`. As we discussed before that in regular expression
194
200
if we put quantifier after character than it will repeats the preceding character. But if we put quantifier after a character group than
@@ -200,7 +206,7 @@ We can also use the alternation `|` meta character inside character group. For e
200
206
"(c|g|p)ar" => The <ahref="#learn-regex"><strong>car</strong></a> is <ahref="#learn-regex"><strong>par</strong></a>ked in the <ahref="#learn-regex"><strong>gar</strong></a>age.
201
207
</pre>
202
208
203
-
## 2.5 Alternation
209
+
## 2.6 Alternation
204
210
205
211
In regular expression Vertical bar `|` is used to define alternation. Alternation is like a condition between multiple expressions. Now,
206
212
you maybe thinking that character set and alternation works the same way. But the big difference between character set and alternation
@@ -212,7 +218,7 @@ or lowercase character `c`, followed by lowercase character `a`, followed by low
212
218
"[T|t]he|car" => <ahref="#learn-regex"><strong>The</strong></a> <ahref="#learn-regex"><strong>car</strong></a> is parked in <ahref="#learn-regex"><strong>the</strong></a> garage.
213
219
</pre>
214
220
215
-
## 2.6 Escaping special character
221
+
## 2.7 Escaping special character
216
222
217
223
Backslash `\` is used in regular expression to escape the next character. This allows to to specify a symbol as a matching character
218
224
including reserved characters `{ } [ ] / \ + * . $ ^ | ?`. To use a special character as a matching character prepend `\` before it.
@@ -224,13 +230,13 @@ expression `[f|c|m]at\.?` means: lowercase letter `f`, `c` or `m`, followed by l
224
230
"[f|c|m]at\.?" => The <ahref="#learn-regex"><strong>fat</strong></a> <ahref="#learn-regex"><strong>cat</strong></a> sat on the <ahref="#learn-regex"><strong>mat.</strong></a>
225
231
</pre>
226
232
227
-
## 2.7 Anchors
233
+
## 2.8 Anchors
228
234
229
235
In regular expression to check if the matching symbol is the starting symbol or endnig symbol of the input string for this purpose
230
236
we use anchors. Anchors are of two types: First type is Caret `^` that check if the matching character is the start character of the
231
237
input and the second type is Dollar `$` that checks if matching character is the last character of the input string.
232
238
233
-
### 2.7.1 Caret
239
+
### 2.8.1 Caret
234
240
235
241
Caret `^` symbol is used to check if matching character is the first character of the input string. If we apply the following regular
236
242
expression `^a` (if a is the starting symbol) to input string `abc` it matches `a`. But if we apply regular expression `^b` on above
@@ -246,7 +252,7 @@ followed by lowercase character `h`, followed by lowercase character `e`.
246
252
"^[T|t]he" => <ahref="#learn-regex"><strong>The</strong></a> car is parked in the garage.
247
253
</pre>
248
254
249
-
### 2.7.2 Dollar
255
+
### 2.8.2 Dollar
250
256
251
257
Dollar `$` symbol is used to check if matching character is the last character of the input string. For example regular expression
252
258
`(at.)$` means: lowercase character `a`, followed by lowercase character `t`, followed by anything except new line and the matcher
0 commit comments