Need one character from several possibilities? Put them in square brackets. `[abc]` matches `a`, `b`, or `c`—one character, not the three-character string `abc`. section 10.2.2
Three useful forms:
- `[abc]` selects one listed character. section 10.2.2
- `[^abc]` selects one character other than `a`, `b`, or `c`. The caret negates the set when it follows the opening bracket; outside brackets, `^` anchors a pattern to the start of a string. section 10.2.2 section 10.7
- `[a-m]` selects one character in the inclusive range from `a` through `m`. section 10.2.2
Matching across a newline
The dot in `/.*/` stops before the newline in `"<b>Hello</b>\n<i>world!</i>"`. The class `[\S\s]` accepts either a non-whitespace or a whitespace character, so `/[\S\s]*/` matches the whole string. Here, `*` repeats the one-character choice. section 10.6.1
Listing 10.11. Matching all characters, including newlines
const html = "<b>Hello</b>\n<i>world!</i>"; #A
assert(/.*/.exec(html)[0] === "<b>Hello</b>", #B
"A normal capture doesn't handle endlines.");
assert(/[\S\s]*/.exec(html)[0] === #C
"<b>Hello</b>\n<i>world!</i>", #C
"Matching everything with a character set."); #C
assert(/(?:.|\s)*/.exec(html)[0] === #D
"<b>Hello</b>\n<i>world!</i>", #D
"Using a non-capturing group to match everything."); #D
Compare the assertions: the dot stops at the newline, while the character class and a non-capturing alternation reach the end. section 10.6.1








