Preg_replace ('/^. +? /U', '', $ auth) to solve this regular expression?

Source: Internet
Author: User
What does this php function mean? Preg_replace (& #039; ^. +? U & #039;, & #039; & #039;, $ auth) What does this php function mean?
Preg_replace ('/^. +? /U', '', $ auth)

Reply content:

What does this php function mean?
Preg_replace ('/^. +? /U', '', $ auth)

FunctionPreg_replaceYou should know how to use regular expressions to replace strings. If you do not understand the regular expression, read the official documentation.

Let me explain this regular expression.'/^. +? /U'.

ModifierUIndicates reversing the greedy mode 」.
Regular Expressions are greedy by default, that is+ *If multiple characters can be matched, try to match more characters unless+? *?.
HoweverUAfter modifier, the greedy mode is not used by default,+ *Non-Greedy match,+? *?Instead, try to match more characters.
For more details, see the official documentation or searchRegular Expression PCRE_UNGREEDY.

So,/^. +? /UActually equivalent/^. +/, Indicates all characters starting from the beginning.

Therefore, this function means to replace all the characters starting from the beginning with an empty string. (Although I don't know what it means to write such a round expression in addition to the interview test)

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