Offer to come, dig friends take it! I am participating in the 2022 Spring Recruit Punch card activity. Click here for details.
ES series of articles
- ES6 variable constant (let const)
- Deconstruction assignment
- ES5 Array traversal mode
- ES6 Array traversal mode
- Extension of arrays
- Arguments to the ES6 function
- Extension operators and REST parameters
- Arrow function
- Object extension
Extension of regular
Regular expressions are used to match strings, and in ES5 there are three modifiers: I (case insensitive) M (multi-line matching) G (global matching). Es6 has two new modifiers: y(adhesion) and U (Unicode).
Regular expression online test tool
– measure words
character | meaning |
---|---|
? | Zero or one occurrence (maximum one occurrence) |
+ | Appear once or more (at least once) |
* | Zero or more occurrences (any occurrence) |
{n} | A n time |
{n,m} | N to m occurrences |
{n,} | At least n |
Border –
character | Equivalence class |
---|---|
^ | Start with XXX |
$ | Ended up with XXX |
\b | Word boundaries |
\B | Non-word boundary |
– Predefined classes
character | Equivalence class | meaning |
---|---|---|
. | [^\r\n] | All characters except carriage returns and newlines |
\d | [0-9] | Numeric characters |
\D | [^ 0-9] | Non-numeric character |
\s | [\t\n\xOB\f\r] | Whitespace characters |
\S | [^\t\n\xOB\f\r] | Non-whitespace character |
\w | [a-zA-Z_0-9] | Word character (alphanumeric underscore) |
\W | [^a-zA-Z_0-9] | Non-word character |
Y modifier
The y modifier is similar to the G modifier in that it is a global match, and each subsequent match starts at the position following the last successful match. The difference is that the G modifier works as long as there is a match in the remaining position, while the Y modifier ensures that the match must start at the first remaining position, which is what “bonding” means.
Const STR = 'aaa_aa_A' const reg1 = /a+/g // The remaining const reg2 = /a+/y // the first remaining start matches console.log(reg1.exec(STR)) console.log(reg2.exec(str)) console.log(reg1.exec(str)) // aa console.log(reg2.exec(str)) // null console.log(reg1.exec(str)) console.log(reg2.exec(str))Copy the code
U modifier
// \u0000~\ uFFFF es5 range const STR = '\ ud8442 \uDFB7' console.log(/^\uD842/.test(STR)) // es5 true console.log(/^\uD842/u.test(str)) // es6 false // . Any single character except newline console.log(/^.$/.test(STR)) // false console.log(/^.$/u.test(STR)) // true The console. The log (/ \ u {61} /. The test (' a ')) / / false console. The log (/ \ u {61} / u.t est (' a ')) / / true console. The log (/ 𠮷 {2} /. The test (' 𠮷 𠮷 ')) / / False to the console. The log (/ 𠮷 {2} / u.t est (' 𠮷 𠮷 ')) / / trueCopy the code
A front end small white, if the article has the wrong content, welcome big guy to give directions to discuss!