Skip to content

Navigation Menu

Sign in
Sign up

fix: save eaten backslash in regexp-escaping article.md ru #2137

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
front42 wants to merge 1 commit into javascript-tutorial:master
base: master
Choose a base branch
Loading
from front42:patch-37
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
4 changes: 2 additions & 2 deletions 9-regular-expressions/07-regexp-escaping/article.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ alert( "1\2円".match(/\\/) ); // '\'

Символ косой черты `'/'`, так называемый "слэш", не является специальным символом, но в JavaScript он используется для открытия и закрытия регулярного выражения: `pattern:/...шаблон.../`, поэтому мы должны экранировать его.

Вот как выглядит поиск самой косой черты `'/'`:
Вот как выглядит поиск косой черты `'/'`:

```js run
alert( "/".match(/\//) ); // '/'
Expand Down Expand Up @@ -64,7 +64,7 @@ alert( "Глава 5.1".match(regexp) ); // null

Причина в том, что символы обратной косой черты "съедаются" строкой. Как вы помните, обычные строки имеют свои специальные символы, такие как `\n`, и для экранирования используется обратная косая черта.

Вот как воспринимается строка "\d\.\d":
Вот как воспринимается строка "\d\\.\d":

```js run
alert("\d\.\d"); // d.d
Expand Down

AltStyle によって変換されたページ (->オリジナル) /