Regular Expressions-PHP regular match preg_match uppercase U lowercase u what are the uses

Source: Internet
Author: User
Found a strange phenomenon, if you add u, the result is not the same, and the uppercase U and lowercase u results are not the same.

Reply content:

Found a strange phenomenon, if you add u, the result is not the same, and the uppercase U and lowercase u results are not the same.


u (PCRE_UTF8)

This modifier opens an additional feature that is incompatible with Perl. The pattern string is considered to be utf-8. This modifier is available from the UNIX version of PHP 4.1.0 or higher, Win32 version of PHP 4.2.3. PHP 4.3.5 start checking the utf-8 legitimacy of the pattern

U (PCRE_UNGREEDY)

This modifier reverses the "greedy" pattern of quantifiers. Make quantifiers default to non-greedy, followed by quantifiers? Way to make it greedy. This is not compatible with Perl. It can also be set using the in-mode modifier (? U), or mark its non-greedy (e.g.. *) with a question mark after the quantifier.

Pattern modifiers


U default to lazy mode, default to greedy mode if not added


One is greedy mode, one is not greedy mode, if greedy mode will output all the results. You can see the PHP Help documentation yourself.

  • 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.