Merge pull request #2363 from vsemozhetbyt/patch-2
Fix some issues in 9.2 (Character classes)
This commit is contained in:
commit
ba5ebbc5f6
1 changed files with 6 additions and 6 deletions
|
@ -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 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
|
||||
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!)
|
||||
```
|
||||
|
||||
````warn header="Not supported in Firefox, IE, Edge"
|
||||
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.
|
||||
````warn header="Not supported in IE"
|
||||
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
|
||||
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.**
|
||||
|
||||
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.
|
||||
````
|
||||
|
@ -198,6 +198,6 @@ There exist following character classes:
|
|||
|
||||
...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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue