You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 9-regular-expressions/03-regexp-character-classes/article.md
+6-5
Original file line number
Diff line number
Diff line change
@@ -89,9 +89,11 @@ When regular expression engine is doing the search, it's moving along the string
89
89
90
90
When the pattern contains `pattern:\b`, it tests that the position in string is a word boundary, that is one of three variants:
91
91
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`.
95
97
96
98
For instance, in the string `subject:Hello, Java!` the following positions match `\b`:
97
99
@@ -101,11 +103,10 @@ So it matches `pattern:\bHello\b`, because:
101
103
102
104
1. At the beginning of the string the first `\b` test matches.
103
105
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).
105
107
106
108
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).
0 commit comments