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
Copy file name to clipboardExpand all lines: README.md
+39-4Lines changed: 39 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,11 +31,10 @@ contains uppercase letter and also it is too short.
31
31
-[Character Group]()
32
32
-[Alternation]()
33
33
-[Escaping special character]()
34
-
-[Quantifiers]()
35
-
-[OR operator]()
36
-
-[Character Sets]()
34
+
-[Anchors]()
35
+
-[Caret]()
36
+
-[Dolar]()
37
37
-[Shorthand Character Sets]()
38
-
-[Grouping]()
39
38
-[Lookaheads]()
40
39
-[Flags]()
41
40
@@ -215,4 +214,40 @@ expression `[f|c|m]at\.?` means: lowercase letter `f`, `c` or `m`, followed by l
215
214
216
215
<pre>
217
216
"[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>
217
+
</pre>
218
+
219
+
## 2.7 Anchors
220
+
221
+
In regular expression to check if the matching symbol is the starting symbol or endnig symbol of the input string for this purpose
222
+
we use anchors. Anchors are of two types: First type is Caret `^` that check if the matching character is the character of the input and the
223
+
second type is Dolar `$` that checks if matching character is the last character of the input string.
224
+
225
+
### 2.7.1 Caret
226
+
227
+
Caret `^` symbol is use to check if matching character is the first character of the input string. If we apply the following regular
228
+
expression `^a` (if a is the starting symbol) to input string `abc` it matches `a`. But if we apply regular expression `^b` on above
229
+
input string it does not match anything. Beacause in input string `abc` "b" is not the starting symbol. Lets take a look on another
230
+
regular expression `^[T|t]he` which means: uppercase character `T` or lowercase character `t` is the start symbol of the input string,
231
+
followed by lowercase character `h`, followed by lowercase character `e`.
232
+
233
+
<pre>
234
+
"[T|t]he" => <ahref="#learn-regex"><strong>The</strong></a> car is parked in <ahref="#learn-regex"><strong>the</strong></a> garage.
235
+
</pre>
236
+
237
+
<pre>
238
+
"^[T|t]he" => <ahref="#learn-regex"><strong>The</strong></a> car is parked in the garage.
239
+
</pre>
240
+
241
+
### 2.7.2 Dolar
242
+
243
+
Dolar `$` symbol is use to check if matching character is the last character of the input string. For example regular expression
244
+
`(at.)$` means: lowercase character `a`, followed by lowercase character `t`, followed by anything except new line and the matcher
245
+
must be end of the string.
246
+
247
+
<pre>
248
+
"(at.)" => The f<ahref="#learn-regex"><strong>at </strong></a>c<ahref="#learn-regex"><strong>at </strong></a>s<ahref="#learn-regex"><strong>at </strong></a>on the m<ahref="#learn-regex"><strong>at.</strong></a>
249
+
</pre>
250
+
251
+
<pre>
252
+
"(at.)$" => The fat cat sat on the m<ahref="#learn-regex"><strong>at.</strong></a>
0 commit comments