Skip to content

Commit 139f678

Browse files
committed
Light pass over chapter 9
1 parent ed4f6a4 commit 139f678

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

09_regexp.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ These backslash codes can also be used inside ((square brackets)). For example,
134134
To _invert_ a set of characters—that is, to express that you want to match any character _except_ the ones in the set—you can write a caret (`^`) character after the opening bracket.
135135

136136
```
137-
let notBinary = /[^01]/;
138-
console.log(notBinary.test("1100100010100110"));
137+
let nonBinary = /[^01]/;
138+
console.log(nonBinary.test("1100100010100110"));
139139
// → false
140-
console.log(notBinary.test("0111010112101001"));
140+
console.log(nonBinary.test("0111010112101001"));
141141
// → true
142142
```
143143

@@ -160,7 +160,7 @@ It is possible to use `\p` in a regular expression to match all characters to wh
160160
| `\p{L}` | Any letter
161161
| `\p{N}` | Any numeric character
162162
| `\p{P}` | Any punctuation character
163-
| `\P{L}` | Any non-letter
163+
| `\P{L}` | Any non-letter (uppercase P inverts)
164164
| `\p{Script=Hangul}` | Any character from the given script (see [Chapter ?](higher_order#scripts))
165165

166166
Using `\w` for text processing that may need to handle non-English text (or even English text with borrowed words like “cliché”) is a liability, since it won't treat characters like “é” as letters. Though they tend to be a bit more verbose, `\p` property groups are more robust.
@@ -292,7 +292,7 @@ console.log(quotedText.exec("she said 'hello'"));
292292

293293
{{index "capture group"}}
294294

295-
When a group does not end up being matched at all (for example, when followed by a question mark), its position in the output array will hold `undefined`. Similarly, when a group is matched multiple times, only the last match ends up in the array.
295+
When a group does not end up being matched at all (for example, when followed by a question mark), its position in the output array will hold `undefined`. And when a group is matched multiple times (for example when it is followed by a `+`), only the last match ends up in the array.
296296

297297
```
298298
console.log(/bad(ly)?/.exec("bad"));
@@ -322,7 +322,7 @@ JavaScript has a standard class for representing ((date))s—or, rather, points
322322

323323
```{test: no}
324324
console.log(new Date());
325-
// → Mon Nov 13 2017 16:19:11 GMT+0100 (CET)
325+
// → Fri Feb 02 2024 18:03:06 GMT+0100 (CET)
326326
```
327327

328328
{{index "Date class"}}
@@ -395,7 +395,7 @@ There is also a `\b` marker, which matches “word boundaries”, positions that
395395

396396
Note that these markers don't match any actual characters. They just enforces that a given condition holds at the place where they appears in the pattern.
397397

398-
{{index "look-ahead}}
398+
{{index "look-ahead"}}
399399

400400
_Look-ahead_ tests do something similar. They provide a pattern, and will make the match fail if the input doesn't match that pattern, but don't actually move the match position forward. They are written between `(?=` and `)`.
401401

@@ -860,7 +860,7 @@ Regular expressions are a sharp ((tool)) with an awkward handle. They simplify s
860860

861861
{{index debugging, bug}}
862862

863-
It is almost unavoidable that, in the course of working on these exercises, you will get confused and frustrated by some regular expression's inexplicable ((behavior)). Sometimes it helps to enter your expression into an online tool like [_https://debuggex.com_](https://www.debuggex.com/) to see whether its visualization corresponds to what you intended and to ((experiment)) with the way it responds to various input strings.
863+
It is almost unavoidable that, in the course of working on these exercises, you will get confused and frustrated by some regular expression's inexplicable ((behavior)). Sometimes it helps to enter your expression into an online tool like [_debuggex.com_](https://www.debuggex.com/) to see whether its visualization corresponds to what you intended and to ((experiment)) with the way it responds to various input strings.
864864

865865
### Regexp golf
866866

@@ -870,7 +870,7 @@ _Code golf_ is a term used for the game of trying to express a particular progra
870870

871871
{{index boundary, matching}}
872872

873-
For each of the following items, write a ((regular expression)) to test whether any of the given substrings occur in a string. The regular expression should match only strings containing one of the substrings described. When your expression works, see whether you can make it any smaller.
873+
For each of the following items, write a ((regular expression)) to test whether the given pattern occurs in a string. The regular expression should match only strings containing the pattern. When your expression works, see whether you can make it any smaller.
874874

875875
1. _car_ and _cat_
876876
2. _pop_ and _prop_

img/re_number.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)