Skip to content

Commit 317c382

Browse files
committed
Fix expression in examples
1 parent b401be1 commit 317c382

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ expression `[Tt]he` means: an uppercase `T` or lowercase `t`, followed by the le
110110
"[Tt]he" => <a href="#learn-regex"><strong>The</strong></a> car parked in <a href="#learn-regex"><strong>the</strong></a> garage.
111111
</pre>
112112

113-
Just like above example the regular expression `ar[.]` means: an lowercase character `a`, followed by letter `r`, followed by any character.
113+
Just like above example the regular expression `ge[.]` means: a lowercase character `g`, followed by letter `e`, followed by `.` character.
114114

115115
<pre>
116-
"ar[.]" => The car p<a href="#learn-regex"><strong>ark</strong></a>ed in the g<a href="#learn-regex"><strong>ara</strong></a>ge.
116+
"ge[.]" => The car parked in the gara<a href="#learn-regex"><strong>ge.</strong></a>
117117
</pre>
118118

119119
### 2.2.1 Negated character set
@@ -211,23 +211,23 @@ We can also use the alternation `|` meta character inside character group. For e
211211
In regular expression Vertical bar `|` is used to define alternation. Alternation is like a condition between multiple expressions. Now,
212212
you maybe thinking that character set and alternation works the same way. But the big difference between character set and alternation
213213
is that character set works on character level but alternation works on expression level. For example the regular expression
214-
`[T|t]he|car` means: uppercase character `T` or lowercase `t`, followed by lowercase character `h`, followed by lowercase character `e`
214+
`(T|t)he|car` means: uppercase character `T` or lowercase `t`, followed by lowercase character `h`, followed by lowercase character `e`
215215
or lowercase character `c`, followed by lowercase character `a`, followed by lowercase character `r`.
216216

217217
<pre>
218-
"[T|t]he|car" => <a href="#learn-regex"><strong>The</strong></a> <a href="#learn-regex"><strong>car</strong></a> is parked in <a href="#learn-regex"><strong>the</strong></a> garage.
218+
"(T|t)he|car" => <a href="#learn-regex"><strong>The</strong></a> <a href="#learn-regex"><strong>car</strong></a> is parked in <a href="#learn-regex"><strong>the</strong></a> garage.
219219
</pre>
220220

221221
## 2.7 Escaping special character
222222

223223
Backslash `\` is used in regular expression to escape the next character. This allows to to specify a symbol as a matching character
224224
including reserved characters `{ } [ ] / \ + * . $ ^ | ?`. To use a special character as a matching character prepend `\` before it.
225225
For example the regular expression `.` is used to match any character except new line. Now to match `.` in an input string the regular
226-
expression `[f|c|m]at\.?` means: lowercase letter `f`, `c` or `m`, followed by lowercase character `a`, followed by lowercase letter
226+
expression `(f|c|m)at\.?` means: lowercase letter `f`, `c` or `m`, followed by lowercase character `a`, followed by lowercase letter
227227
`t`, followed by optional `.` character.
228228

229229
<pre>
230-
"[f|c|m]at\.?" => The <a href="#learn-regex"><strong>fat</strong></a> <a href="#learn-regex"><strong>cat</strong></a> sat on the <a href="#learn-regex"><strong>mat.</strong></a>
230+
"(f|c|m)at\.?" => The <a href="#learn-regex"><strong>fat</strong></a> <a href="#learn-regex"><strong>cat</strong></a> sat on the <a href="#learn-regex"><strong>mat.</strong></a>
231231
</pre>
232232

233233
## 2.8 Anchors
@@ -241,29 +241,29 @@ input and the second type is Dollar `$` that checks if matching character is the
241241
Caret `^` symbol is used to check if matching character is the first character of the input string. If we apply the following regular
242242
expression `^a` (if a is the starting symbol) to input string `abc` it matches `a`. But if we apply regular expression `^b` on above
243243
input string it does not match anything. Because in input string `abc` "b" is not the starting symbol. Let's take a look on another
244-
regular expression `^[T|t]he` which means: uppercase character `T` or lowercase character `t` is the start symbol of the input string,
244+
regular expression `^(T|t)he` which means: uppercase character `T` or lowercase character `t` is the start symbol of the input string,
245245
followed by lowercase character `h`, followed by lowercase character `e`.
246246

247247
<pre>
248-
"[T|t]he" => <a href="#learn-regex"><strong>The</strong></a> car is parked in <a href="#learn-regex"><strong>the</strong></a> garage.
248+
"(T|t)he" => <a href="#learn-regex"><strong>The</strong></a> car is parked in <a href="#learn-regex"><strong>the</strong></a> garage.
249249
</pre>
250250

251251
<pre>
252-
"^[T|t]he" => <a href="#learn-regex"><strong>The</strong></a> car is parked in the garage.
252+
"^(T|t)he" => <a href="#learn-regex"><strong>The</strong></a> car is parked in the garage.
253253
</pre>
254254

255255
### 2.8.2 Dollar
256256

257257
Dollar `$` symbol is used to check if matching character is the last character of the input string. For example regular expression
258-
`(at.)$` means: lowercase character `a`, followed by lowercase character `t`, followed by anything except new line and the matcher
258+
`(at\.)$` means: a lowercase character `a`, followed by lowercase character `t`, followed by a `.` character and the matcher
259259
must be end of the string.
260260

261261
<pre>
262-
"(at.)" => The f<a href="#learn-regex"><strong>at </strong></a>c<a href="#learn-regex"><strong>at </strong></a>s<a href="#learn-regex"><strong>at </strong></a>on the m<a href="#learn-regex"><strong>at.</strong></a>
262+
"(at\.)" => The fat c<a href="#learn-regex"><strong>at.</strong></a> s<a href="#learn-regex"><strong>at.</strong></a> on the m<a href="#learn-regex"><strong>at.</strong></a>
263263
</pre>
264264

265265
<pre>
266-
"(at.)$" => The fat cat sat on the m<a href="#learn-regex"><strong>at.</strong></a>
266+
"(at\.)$" => The fat cat sat on the m<a href="#learn-regex"><strong>at.</strong></a>
267267
</pre>
268268

269269
## 3. Shorthand Character Sets
@@ -301,43 +301,43 @@ by `$` character. Following are the lookarounds that are used in regular express
301301
The positive lookahead asserts that the first part of the expression must be followed by the lookahead expression. The returned match
302302
only contains the text that is matched by the first part of the expression. To define a positive lookahead braces are used and within
303303
those braces question mark with equal sign is used like this `(?=...)`. Lookahead expression is written after the equal sign inside
304-
braces. For example the regular expression `[T|t]he(?=\sfat)` means: optionally match lowercase letter `t` or uppercase letter `T`,
304+
braces. For example the regular expression `(T|t)he(?=\sfat)` means: optionally match lowercase letter `t` or uppercase letter `T`,
305305
followed by letter `h`, followed by letter `e`. In braces we define positive lookahead which tells regular expression engine to match
306306
`The` or `the` which are followed by the word `fat`.
307307

308308
<pre>
309-
"[T|t]he(?=\sfat)" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
309+
"(T|t)he(?=\sfat)" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
310310
</pre>
311311

312312
### 4.2 Negative Lookahead
313313

314314
Negative lookahead is used when we need to get all matches from input string that are not followed by a pattern. Negative lookahead
315315
defined same as we define positive lookahead but the only difference is instead of equal `=` character we use negation `!` character
316-
i.e. `(?!...)`. Let's take a look at the following regular expression `[T|t]he(?!\sfat)` which means: get all `The` or `the` words from
316+
i.e. `(?!...)`. Let's take a look at the following regular expression `(T|t)he(?!\sfat)` which means: get all `The` or `the` words from
317317
input string that are not followed by the word `fat` precedes by a space character.
318318

319319
<pre>
320-
"[T|t]he(?!\sfat)" => The fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
320+
"(T|t)he(?!\sfat)" => The fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
321321
</pre>
322322

323323
### 4.3 Positive Lookbehind
324324

325325
Positive lookbehind is used to get all the matches that are preceded by a specific pattern. Positive lookbehind is denoted by
326-
`(?<=...)`. For example the regular expression `(?<=[T|t]he\s)(fat|mat)` means: get all `fat` or `mat` words from input string that
326+
`(?<=...)`. For example the regular expression `(?<=(T|t)he\s)(fat|mat)` means: get all `fat` or `mat` words from input string that
327327
are after the word `The` or `the`.
328328

329329
<pre>
330-
"(?<=[T|t]he\s)(fat|mat)" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the <a href="#learn-regex"><strong>mat</strong></a>.
330+
"(?<=(T|t)he\s)(fat|mat)" => The <a href="#learn-regex"><strong>fat</strong></a> cat sat on the <a href="#learn-regex"><strong>mat</strong></a>.
331331
</pre>
332332

333333
### 4.4 Negative Lookbehind
334334

335335
Negative lookbehind is used to get all the matches that are not preceded by a specific pattern. Negative lookbehind is denoted by
336-
`(?<!...)`. For example the regular expression `(?&lt;![T|t]he\s)(cat)` means: get all `cat` words from input string that
336+
`(?<!...)`. For example the regular expression `(?&lt;!(T|t)he\s)(cat)` means: get all `cat` words from input string that
337337
are after not after the word `The` or `the`.
338338

339339
<pre>
340-
"(?&lt;![T|t]he\s)(cat)" => The cat sat on <a href="#learn-regex"><strong>cat</strong></a>.
340+
"(?&lt;!(T|t)he\s)(cat)" => The cat sat on <a href="#learn-regex"><strong>cat</strong></a>.
341341
</pre>
342342

343343
## 5. Flags

0 commit comments

Comments
 (0)