New users seek advice ~ Why do I feel useless about the regular expression pattern modifier e?

Source: Internet
Author: User
New users seek advice ~ Why do I feel useless about the regular expression pattern modifier e? For example, the two pieces of code match the URL link in the string. This uses the pattern modifier e: $ urlPattern & nbsp; (www. | https? : | Ftp: | news: | telnet :) {1} ([^ [] + ?) (Com | net | org) ([w -.? New users seek advice ~ Why do I feel useless about the regular expression pattern modifier e?
For example, the two codes match the URL link in the string.

Here is the pattern modifier e:

$ UrlPattern = "/(www. | https? : \/| Ftp: \/| news: \/| telnet :\/\/) {1} ([^ \ [\ "'] + ?) (Com | net | org) (\/[\ w -\.\/\? \ % \ & \ =] *)? /Ei ";

$ Url = "PHP address: www.php.com ";

Echo preg_replace ($ urlPattern, "'\ 2'.' \ 3'", $ url );


Here is the pattern modifier e:

$ UrlPattern = "/(www. | https? : \/| Ftp: \/| news: \/| telnet :\/\/) {1} ([^ \ [\ "'] + ?) (Com | net | org) (\/[\ w -\.\/\? \ % \ & \ =] *)? /I ";

$ Url = "PHP address: www.php.com ";

Echo preg_replace ($ urlPattern, '\ 2'.' \ 3', $ url );

The output results are the same ~
All of them are replacing www.php.com with php.com.

I think that's just a matter of double quotation marks ,,,
Instead, it's easier to use e.

What is e?

Regular PHP

Share:


------ Solution --------------------
E (PREG_REPLACE_EVAL)
If this modifier is set, preg_replace () will evaluate and execute the replaced string as php code (eval function mode) after the replacement string is replaced by a reference ), and use the execution result as the string to be replaced. Single quotation marks, double quotation marks, backslash (\), and NULL characters are escaped by backslash when being replaced by backward references.

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.