From 3ed1024ae786015867f842c390ddb1bcf9435780 Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Wed, 21 Aug 2019 12:32:58 +0300 Subject: [PATCH] minor --- .../01-regexp-introduction/article.md | 8 +++++++- .../03-regexp-character-classes/article.md | 11 ++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/9-regular-expressions/01-regexp-introduction/article.md b/9-regular-expressions/01-regexp-introduction/article.md index 57fe02f5..1632a930 100644 --- a/9-regular-expressions/01-regexp-introduction/article.md +++ b/9-regular-expressions/01-regexp-introduction/article.md @@ -1,10 +1,16 @@ # Patterns and flags +Regular expressions is a powerful way to search and replace in text. + +In JavaScript, they are available as `RegExp` object, and also integrated in methods of strings. + +## Regular Expressions + A regular expression (also "regexp", or just "reg") consists of a *pattern* and optional *flags*. There are two syntaxes to create a regular expression object. -The long syntax: +The "long" syntax: ```js regexp = new RegExp("pattern", "flags"); diff --git a/9-regular-expressions/03-regexp-character-classes/article.md b/9-regular-expressions/03-regexp-character-classes/article.md index 91162216..8e18df91 100644 --- a/9-regular-expressions/03-regexp-character-classes/article.md +++ b/9-regular-expressions/03-regexp-character-classes/article.md @@ -89,9 +89,11 @@ When regular expression engine is doing the search, it's moving along the string When the pattern contains `pattern:\b`, it tests that the position in string is a word boundary, that is one of three variants: -- Immediately before is `\w`, and immediately after -- not `\w`, or vise versa. -- At string start, and the first string character is `\w`. -- At string end, and the last string character is `\w`. +There are three different positions that qualify as word boundaries: + +- At string start, if the first string character is a word character `\w`. +- Between two characters in the string, where one is a word character `\w` and the other is not. +- At string end, if the last string character is a word character `\w`. For instance, in the string `subject:Hello, Java!` the following positions match `\b`: @@ -101,11 +103,10 @@ So it matches `pattern:\bHello\b`, because: 1. At the beginning of the string the first `\b` test matches. 2. Then the word `Hello` matches. -3. Then `\b` matches, as we're between `o` and a space. +3. Then `\b` matches, as we're between `o` (a word character) and a space (not a word character). Pattern `pattern:\bJava\b` also matches. But not `pattern:\bHell\b` (because there's no word boundary after `l`) and not `Java!\b` (because the exclamation sign is not a wordly character, so there's no word boundary after it). - ```js run alert( "Hello, Java!".match(/\bHello\b/) ); // Hello alert( "Hello, Java!".match(/\bJava\b/) ); // Java