Regular Expression u modifier (UTF-16 encoding supported), regular expression UTF-16

Source: Internet
Author: User

Regular Expression u modifier (UTF-16 encoding supported), regular expression UTF-16

Regular Expression u modifier:

This modifier identifies Unicode characters greater than \ uFFFF.
That is, the UTF-16 encoding of four bytes is processed correctly.
This modifier is added to ES2015. For more features of regular expressions, see section 1 "New Features of ES2015 regular expressions.
For more regular expression tutorials, see the regular expression tutorial section.

Code example:

Console. log (/^ \ uD842/u. test ("\ uD842 \ uDFB7 "))

The output is false, because "\ uD842 \ uDFB7" is a four-byte UTF-16 encoded, representing a character, so if the regular expression carries a u modifier, it can be recognized.

Console. log (/^ \ uD842/. test ("\ uD842 \ uDFB7 "))

Output true; without the u modifier, the four-byte UTF-16 encoding cannot be recognized as a character, so a match can be produced.

/^. $/. Test ("\ uD842 \ uDFB7") // false/^. $/u. test ("\ uD842 \ uDFB7")/true

For usage of metacharacters (.), see section 1 of the regular expression. No. metacharacters.

/^. $/. Test ("\ uD842 \ uDFB7") // false/^. $/u. test ("\ uD842 \ uDFB7")/true

After the u modifier is added, the dot metacharacters can match Unicode characters with a code point greater than 0xFFFF.

/\ U {61}/. test ("a") // false/\ u {61}/u. test ("a") // true

Using the u modifier, the regular expression can recognize Unicode characters represented by braces {}. Otherwise, the regular expression cannot be recognized. {61} will also be interpreted as quantifiers, representing 61 u characters.
For more information about Unicode characters in braces, see the section "ES2015 new feature.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.