Skip to content

Commit 3ed1024

Browse files
committed
minor
1 parent 047ebc8 commit 3ed1024

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

9-regular-expressions/01-regexp-introduction/article.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# Patterns and flags
22

3+
Regular expressions is a powerful way to search and replace in text.
4+
5+
In JavaScript, they are available as `RegExp` object, and also integrated in methods of strings.
6+
7+
## Regular Expressions
8+
39
A regular expression (also "regexp", or just "reg") consists of a *pattern* and optional *flags*.
410

511
There are two syntaxes to create a regular expression object.
612

7-
The long syntax:
13+
The "long" syntax:
814

915
```js
1016
regexp = new RegExp("pattern", "flags");

9-regular-expressions/03-regexp-character-classes/article.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ When regular expression engine is doing the search, it's moving along the string
8989

9090
When the pattern contains `pattern:\b`, it tests that the position in string is a word boundary, that is one of three variants:
9191

92-
- Immediately before is `\w`, and immediately after -- not `\w`, or vise versa.
93-
- At string start, and the first string character is `\w`.
94-
- At string end, and the last string character is `\w`.
92+
There are three different positions that qualify as word boundaries:
93+
94+
- At string start, if the first string character is a word character `\w`.
95+
- Between two characters in the string, where one is a word character `\w` and the other is not.
96+
- At string end, if the last string character is a word character `\w`.
9597

9698
For instance, in the string `subject:Hello, Java!` the following positions match `\b`:
9799

@@ -101,11 +103,10 @@ So it matches `pattern:\bHello\b`, because:
101103

102104
1. At the beginning of the string the first `\b` test matches.
103105
2. Then the word `Hello` matches.
104-
3. Then `\b` matches, as we're between `o` and a space.
106+
3. Then `\b` matches, as we're between `o` (a word character) and a space (not a word character).
105107

106108
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).
107109

108-
109110
```js run
110111
alert( "Hello, Java!".match(/\bHello\b/) ); // Hello
111112
alert( "Hello, Java!".match(/\bJava\b/) ); // Java

0 commit comments

Comments
 (0)