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
The `*` symbol can be used with the meta character `.` to match any string of characters `.*`. The `*` symbol can be used with the
146
-
whitespace character `\s` to match a string of whitespace characters. For example the expression `\s*cat\s*` means: zero or more
146
+
whitespace character `\s` to match a string of whitespace characters. For example, the expression `\s*cat\s*` means: zero or more
147
147
spaces, followed by lowercase character `c`, followed by lowercase character `a`, followed by lowercase character `t`, followed by
148
148
zero or more spaces.
149
149
@@ -153,7 +153,7 @@ zero or more spaces.
153
153
154
154
### 2.3.2 The Plus
155
155
156
-
The symbol `+` matches one or more repetitions of the preceding character. For example the regular expression `c.+t` means: lowercase
156
+
The symbol `+` matches one or more repetitions of the preceding character. For example, the regular expression `c.+t` means: lowercase
157
157
letter `c`, followed by any number of character, followed by the lowercase character `t`.
158
158
159
159
<pre>
@@ -163,7 +163,7 @@ letter `c`, followed by any number of character, followed by the lowercase chara
163
163
### 2.3.3 The Question Mark
164
164
165
165
In regular expression the meta character `?` makes the preceding character optional. This symbol matches zero or one instance of
166
-
the preceding character. For example the regular expression `[T]?he` means: Optional the uppercase letter `T`, followed by the lowercase
166
+
the preceding character. For example, the regular expression `[T]?he` means: Optional the uppercase letter `T`, followed by the lowercase
167
167
character `h`, followed by the lowercase character `e`.
168
168
169
169
<pre>
@@ -176,14 +176,14 @@ character `h`, followed by the lowercase character `e`.
176
176
## 2.4 Braces
177
177
178
178
In regular expression braces that are also called quantifiers are used to specify the number of times that a
179
-
character or a group of characters can be repeated. For example the regular expression `[0-9]{2,3}` means: Match at least 2 digits but not more than 3 (
179
+
character or a group of characters can be repeated. For example, the regular expression `[0-9]{2,3}` means: Match at least 2 digits but not more than 3 (
180
180
characters in the range of 0 to 9).
181
181
182
182
<pre>
183
183
"[0-9]{2,3}" => The number was 9.<ahref="#learn-regex"><strong>999</strong></a>7 but we rounded it off to <ahref="#learn-regex"><strong>10</strong></a>.0.
184
184
</pre>
185
185
186
-
We can leave out the second number. For example the regular expression `[0-9]{2,}` means: Match 2 or more digits. If we also remove
186
+
We can leave out the second number. For example, the regular expression `[0-9]{2,}` means: Match 2 or more digits. If we also remove
187
187
the comma the regular expression `[0-9]{2}` means: Match exactly 2 digits.
188
188
189
189
<pre>
@@ -198,8 +198,8 @@ the comma the regular expression `[0-9]{2}` means: Match exactly 2 digits.
198
198
199
199
Character group is a group of sub-pattern that is written inside Parentheses `(...)`. As we discussed before that in regular expression
200
200
if we put a quantifier after a character than it will repeat the preceding character. But if we put quantifier after a character group then
201
-
it repeats the whole character group. For example the regular expression `(ab)*` matches zero or more repetitions of the character "ab".
202
-
We can also use the alternation `|` meta character inside character group. For example the regular expression `(c|g|p)ar` means: lowercase character `c`,
201
+
it repeats the whole character group. For example, the regular expression `(ab)*` matches zero or more repetitions of the character "ab".
202
+
We can also use the alternation `|` meta character inside character group. For example, the regular expression `(c|g|p)ar` means: lowercase character `c`,
203
203
`g` or `p`, followed by character `a`, followed by character `r`.
204
204
205
205
<pre>
@@ -209,8 +209,8 @@ We can also use the alternation `|` meta character inside character group. For e
209
209
## 2.6 Alternation
210
210
211
211
In regular expression Vertical bar `|` is used to define alternation. Alternation is like a condition between multiple expressions. Now,
212
-
you maybe thinking that character set and alternation works the same way. But the big difference between character set and alternation
213
-
is that character set works on character level but alternation works on expression level. For example the regular expression
212
+
you may be thinking that character set and alternation works the same way. But the big difference between character set and alternation
213
+
is that character set works on character level but alternation works on expression level. For example, the regular expression
214
214
`(T|t)he|car` means: uppercase character `T` or lowercase `t`, followed by lowercase character `h`, followed by lowercase character `e`
215
215
or lowercase character `c`, followed by lowercase character `a`, followed by lowercase character `r`.
216
216
@@ -222,7 +222,7 @@ or lowercase character `c`, followed by lowercase character `a`, followed by low
222
222
223
223
Backslash `\` is used in regular expression to escape the next character. This allows to to specify a symbol as a matching character
224
224
including reserved characters `{ } [ ] / \ + * . $ ^ | ?`. To use a special character as a matching character prepend `\` before it.
225
-
For example the regular expression `.` is used to match any character except new line. Now to match `.` in an input string the regular
225
+
For example, the regular expression `.` is used to match any character except new line. Now to match `.` in an input string the regular
226
226
expression `(f|c|m)at\.?` means: lowercase letter `f`, `c` or `m`, followed by lowercase character `a`, followed by lowercase letter
227
227
`t`, followed by optional `.` character.
228
228
@@ -254,7 +254,7 @@ followed by lowercase character `h`, followed by lowercase character `e`.
254
254
255
255
### 2.8.2 Dollar
256
256
257
-
Dollar `$` symbol is used to check if matching character is the last character of the input string. For example regular expression
257
+
Dollar `$` symbol is used to check if matching character is the last character of the input string. For example, regular expression
258
258
`(at\.)$` means: a lowercase character `a`, followed by lowercase character `t`, followed by a `.` character and the matcher
259
259
must be end of the string.
260
260
@@ -285,7 +285,7 @@ regular expressions. The shorthand character sets are as follows:
285
285
286
286
Lookbehind and lookahead sometimes known as lookaround are specific type of ***non-capturing group*** (Use to match the pattern but not
287
287
included in matching list). Lookaheads are used when we have the condition that this pattern is preceded or followed by another certain
288
-
pattern. For example we want to get all numbers that are preceded by `$` character from the following input string `$4.44 and $10.88`.
288
+
pattern. For example, we want to get all numbers that are preceded by `$` character from the following input string `$4.44 and $10.88`.
289
289
We will use following regular expression `(?<=\$)[0-9\.]*` which means: get all the numbers which contains `.` character and preceded
290
290
by `$` character. Following are the lookarounds that are used in regular expressions:
291
291
@@ -301,7 +301,7 @@ by `$` character. Following are the lookarounds that are used in regular express
301
301
The positive lookahead asserts that the first part of the expression must be followed by the lookahead expression. The returned match
302
302
only contains the text that is matched by the first part of the expression. To define a positive lookahead braces are used and within
303
303
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`,
305
305
followed by letter `h`, followed by letter `e`. In braces we define positive lookahead which tells regular expression engine to match
306
306
`The` or `the` which are followed by the word `fat`.
307
307
@@ -323,7 +323,7 @@ input string that are not followed by the word `fat` precedes by a space charact
323
323
### 4.3 Positive Lookbehind
324
324
325
325
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
327
327
are after the word `The` or `the`.
328
328
329
329
<pre>
@@ -333,8 +333,8 @@ are after the word `The` or `the`.
333
333
### 4.4 Negative Lookbehind
334
334
335
335
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 `(?<!(T|t)he\s)(cat)` means: get all `cat` words from input string that
337
-
are after not after the word `The` or `the`.
336
+
`(?<!...)`. For example, the regular expression `(?<!(T|t)he\s)(cat)` means: get all `cat` words from input string that
337
+
are not after the word `The` or `the`.
338
338
339
339
<pre>
340
340
"(?<!(T|t)he\s)(cat)" => The cat sat on <ahref="#learn-regex"><strong>cat</strong></a>.
@@ -353,7 +353,7 @@ combination, and are an integral part of the RegExp.
353
353
354
354
### 5.1 Case Insensitive
355
355
356
-
The `i` modifier is used to perform case-insensitive matching. For example the regular expression `/The/gi` means: uppercase letter
356
+
The `i` modifier is used to perform case-insensitive matching. For example, the regular expression `/The/gi` means: uppercase letter
357
357
`T`, followed by lowercase character `h`, followed by character `e`. And at the end of regular expression the `i` flag tells the
358
358
regular expression engine to ignore the case. As you can see we also provided `g` flag because we want to search for the pattern in
359
359
the whole input string.
@@ -369,7 +369,7 @@ the whole input string.
369
369
### 5.2 Global search
370
370
371
371
372
-
The `g` modifier is used to perform a global match (find all matches rather than stopping after the first match). For example the
372
+
The `g` modifier is used to perform a global match (find all matches rather than stopping after the first match). For example, the
373
373
regular expression`/.(at)/g` means: any character except new line, followed by lowercase character `a`, followed by lowercase
374
374
character `t`. Because we provided `g` flag at the end of the regular expression now it will find every matches from whole input
375
375
string.
@@ -386,8 +386,8 @@ string.
386
386
387
387
### 5.3 Multiline
388
388
389
-
The `m` modifier is used to perform a multiline match. As we discussed earlier anchors `(^, $)` are used to check if pattern is
390
-
the beginning of the input or end of the input string. But if we want that anchors works on each line we use `m` flag. For example the
389
+
The `m` modifier is used to perform a multi-line match. As we discussed earlier anchors `(^, $)` are used to check if pattern is
390
+
the beginning of the input or end of the input string. But if we want that anchors works on each line we use `m` flag. For example, the
391
391
regular expression `/at(.)?$/gm` means: lowercase character `a`, followed by lowercase character `t`, optionally anything except new
392
392
line. And because of `m` flag now regular expression engine matches pattern at the end of each line in a string.
0 commit comments