mirror of
https://github.com/ziishaned/learn-regex.git
synced 2025-09-08 06:36:02 -04:00
Fix #86 - Replace character set with character group
This commit is contained in:
parent
c38baf18f4
commit
17571a9d82
14
README.md
14
README.md
@ -405,13 +405,13 @@ that is matched by the first part of the expression. To define a positive
|
||||
lookahead, parentheses are used. Within those parentheses, a question mark with
|
||||
equal sign is used like this: `(?=...)`. Lookahead expression is written after
|
||||
the equal sign inside parentheses. For example, the regular expression
|
||||
`[T|t]he(?=\sfat)` means: optionally match lowercase letter `t` or uppercase
|
||||
`(T|t)he(?=\sfat)` means: optionally match lowercase letter `t` or uppercase
|
||||
letter `T`, followed by letter `h`, followed by letter `e`. In parentheses we
|
||||
define positive lookahead which tells regular expression engine to match `The`
|
||||
or `the` which are followed by the word `fat`.
|
||||
|
||||
<pre>
|
||||
"[T|t]he(?=\sfat)" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
|
||||
"(T|t)he(?=\sfat)" => <a href="#learn-regex"><strong>The</strong></a> fat cat sat on the mat.
|
||||
</pre>
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/IDDARt/1)
|
||||
@ -422,12 +422,12 @@ Negative lookahead is used when we need to get all matches from input string
|
||||
that are not followed by a pattern. Negative lookahead defined same as we define
|
||||
positive lookahead but the only difference is instead of equal `=` character we
|
||||
use negation `!` character i.e. `(?!...)`. Let's take a look at the following
|
||||
regular expression `[T|t]he(?!\sfat)` which means: get all `The` or `the` words
|
||||
regular expression `(T|t)he(?!\sfat)` which means: get all `The` or `the` words
|
||||
from input string that are not followed by the word `fat` precedes by a space
|
||||
character.
|
||||
|
||||
<pre>
|
||||
"[T|t]he(?!\sfat)" => The fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
|
||||
"(T|t)he(?!\sfat)" => The fat cat sat on <a href="#learn-regex"><strong>the</strong></a> mat.
|
||||
</pre>
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/V32Npg/1)
|
||||
@ -436,11 +436,11 @@ character.
|
||||
|
||||
Positive lookbehind is used to get all the matches that are preceded by a
|
||||
specific pattern. Positive lookbehind is denoted by `(?<=...)`. For example, the
|
||||
regular expression `(?<=[T|t]he\s)(fat|mat)` means: get all `fat` or `mat` words
|
||||
regular expression `(?<=(T|t)he\s)(fat|mat)` means: get all `fat` or `mat` words
|
||||
from input string that are after the word `The` or `the`.
|
||||
|
||||
<pre>
|
||||
"(?<=[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>.
|
||||
"(?<=(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>.
|
||||
</pre>
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/avH165/1)
|
||||
@ -453,7 +453,7 @@ regular expression `(?<!(T|t)he\s)(cat)` means: get all `cat` words from input
|
||||
string that are not after the word `The` or `the`.
|
||||
|
||||
<pre>
|
||||
"(?<![T|t]he\s)(cat)" => The cat sat on <a href="#learn-regex"><strong>cat</strong></a>.
|
||||
"(?<!(T|t)he\s)(cat)" => The cat sat on <a href="#learn-regex"><strong>cat</strong></a>.
|
||||
</pre>
|
||||
|
||||
[Test the regular expression](https://regex101.com/r/8Efx5G/1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user