Skip to content

New flag in regular expressions: d #3552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions 9-regular-expressions/01-regexp-introduction/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ let regexp = new RegExp(`<${tag}>`); // same as /<h2>/ if answered "h2" in the p

## Flags

Regular expressions may have flags that affect the search.
Regular expressions may have flags that affect the search or provide additional information.

There are only 6 of them in JavaScript:
There are only 7 of them in JavaScript:

`pattern:i`
: With this flag the search is case-insensitive: no difference between `A` and `a` (see the example below).
Expand All @@ -61,6 +61,9 @@ There are only 6 of them in JavaScript:
`pattern:y`
: "Sticky" mode: searching at the exact position in the text (covered in the chapter <info:regexp-sticky>)

`pattern:d`
: With this flag, the result of the regular expression is placed in an array which contains additional information about the regular expression, such as the start and end indices of the substring. This flag does not change the behavior of the regular expression, it just provides additional information.

```smart header="Colors"
From here on the color scheme is:

Expand Down Expand Up @@ -170,7 +173,7 @@ Full information about the methods is given in the article <info:regexp-methods>

## Summary

- A regular expression consists of a pattern and optional flags: `pattern:g`, `pattern:i`, `pattern:m`, `pattern:u`, `pattern:s`, `pattern:y`.
- A regular expression consists of a pattern and optional flags: `pattern:g`, `pattern:i`, `pattern:m`, `pattern:u`, `pattern:s`, `pattern:y`, `pattern:d`.
- Without flags and special symbols (that we'll study later), the search by a regexp is the same as a substring search.
- The method `str.match(regexp)` looks for matches: all of them if there's `pattern:g` flag, otherwise, only the first one.
- The method `str.replace(regexp, replacement)` replaces matches found using `regexp` with `replacement`: all of them if there's `pattern:g` flag, otherwise only the first one.
Expand Down