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
+14-1Lines changed: 14 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,7 @@ contains uppercase letter and also it is too short.
29
29
-[The Plus]()
30
30
-[The Question Mark]()
31
31
-[Character Group]()
32
+
-[Alternation]()
32
33
-[Quantifiers]()
33
34
-[OR operator]()
34
35
-[Character Sets]()
@@ -184,9 +185,21 @@ the comma the regular expression `[0-9]{2}` means: Match exactly 2 digits.
184
185
Character group is a group of sub-pattern that is written inside Parentheses `(...)`. As we discussed before that in regular expression
185
186
if we put quantifier after character than it will repeats the preceding character. But if we put quantifier after a character group than
186
187
it repeats the whole character group. For example the regular expression `(ab)*` matches zero or more repetitions of the character "ab".
187
-
We can also use the alternation inside character group. For example the regular expression `(c|g|p)ar` means: lowercase character `c`,
188
+
We can also use the alternation `|` meta character inside character group. For example the regular expression `(c|g|p)ar` means: lowercase character `c`,
188
189
`g` or `p`, followed by character `a`, followed by character `r`.
189
190
190
191
<pre>
191
192
"(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.
193
+
</pre>
194
+
195
+
## 2.5 Alternation
196
+
197
+
In regular expression Vertical bar `|` is used to define alternation. Alternation is like a condition between multiple expressions. Now,
198
+
you maybe thinking that character set and alternation works the same way. But the big difference between character set and alternation
199
+
is that character set works on character level but alternation works on expression level. For example the regular expression
200
+
`[T|t]he|car` means: uppercase character `T` or lowercase `t`, followed by lowercase character `h`, followed by lowercase character `e`
201
+
or lowercase character `c`, followed by lowercase character `a`, followed by lowercase character `r`.
202
+
203
+
<pre>
204
+
"[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.
0 commit comments