Fix some issues in 9.2 (Character classes)

* Fix typos.
* Update a support note.
* Add a reference for a yet unexplained pattern.
This commit is contained in:
Vse Mozhe Buty 2020-12-07 17:42:51 +02:00
parent e87f130fc1
commit 2cf95d82ba

View file

@ -8,7 +8,7 @@ A *character class* is a special notation that matches any symbol from a certain
For the start, let's explore the "digit" class. It's written as `pattern:\d` and corresponds to "any single digit". For the start, let's explore the "digit" class. It's written as `pattern:\d` and corresponds to "any single digit".
For instance, the let's find the first digit in the phone number: For instance, let's find the first digit in the phone number:
```js run ```js run
let str = "+7(903)-123-45-67"; let str = "+7(903)-123-45-67";
@ -144,10 +144,10 @@ That's what flag `pattern:s` does. If a regexp has it, then a dot `pattern:.` ma
alert( "A\nB".match(/A.B/s) ); // A\nB (match!) alert( "A\nB".match(/A.B/s) ); // A\nB (match!)
``` ```
````warn header="Not supported in Firefox, IE, Edge" ````warn header="Not supported in IE"
Check <https://caniuse.com/#search=dotall> for the most recent state of support. At the time of writing it doesn't include Firefox, IE, Edge. The `pattern:s` flag is not supported in IE.
Luckily, there's an alternative, that works everywhere. We can use a regexp like `pattern:[\s\S]` to match "any character". Luckily, there's an alternative, that works everywhere. We can use a regexp like `pattern:[\s\S]` to match "any character" (this pattern will be covered in the article <info:regexp-character-sets-and-ranges>).
```js run ```js run
alert( "A\nB".match(/A[\s\S]B/) ); // A\nB (match!) alert( "A\nB".match(/A[\s\S]B/) ); // A\nB (match!)
@ -179,7 +179,7 @@ alert( "1 - 5".match(/\d\s-\s\d/) ); // 1 - 5, also works
**A space is a character. Equal in importance with any other character.** **A space is a character. Equal in importance with any other character.**
We can't add or remove spaces from a regular expression and expect to work the same. We can't add or remove spaces from a regular expression and expect it to work the same.
In other words, in a regular expression all characters matter, spaces too. In other words, in a regular expression all characters matter, spaces too.
```` ````
@ -198,6 +198,6 @@ There exist following character classes:
...But that's not all! ...But that's not all!
Unicode encoding, used by JavaScript for strings, provides many properties for characters, like: which language the letter belongs to (if it's a letter) it is it a punctuation sign, etc. Unicode encoding, used by JavaScript for strings, provides many properties for characters, like: which language the letter belongs to (if it's a letter), is it a punctuation sign, etc.
We can search by these properties as well. That requires flag `pattern:u`, covered in the next article. We can search by these properties as well. That requires flag `pattern:u`, covered in the next article.