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