Php regular expression replacement variable specifies the character method

Source: Internet
Author: User
This article mainly introduces the php regular expression replacement variable specified character method, involves the php regular expression for string replacement techniques, very practical value, for more information about how to replace the specified characters in a regular expression in php, see the following example. Share it with you for your reference. The details are as follows:

Three common methods are introduced here.

Method 1:

 

Method 2:

 

Method 3:

 

All three methods return the same result. The Perl-style regular expression in PHP is exactly the same as that in Perl. quotemeta is also common ..

Some other regular expressions

Example:

$ Text = "foobar123fooabcbar"; $ text = preg_replace ("/foo (? = Bar)/"," *** ", $ text); // match the position in front of the bar *** bar123fooabcbar
$ Text = "foobar123fooabcbar"; $ text = preg_replace ("/(? <= Bar) 123/"," *** ", $ text); // match the position foo *** 123 fooabcbar behind the bar
$ Text = "foobar123fooabcbar"; $ text = preg_replace ("/foo (?! Bar)/"," *** ", $ text); // match the position behind the bar instead of foobar123 *** abcbar
$ Text = "foobar123fooabcbar"; $ text = preg_replace ("/(?
 

I hope this article will help you with php programming.

For more articles about the php regular expression replacement variable's specific character method, please follow the PHP Chinese network!

Related articles:

Explanation of the most common regular expressions in PHP

Php regular expression filtering code for html tags, spaces, and line breaks

Analysis on matching, replacing, and splitting functions of PHP regular expressions

PHP development skills (12)-examples of common PHP regular expressions

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.