We know Perl-compatible regular expressions in PHP, so what do we need to know about Ereg regular expressions? Here we introduce you to the Ereg regular expressions by using Perl-compatible regular expressions and perl/ereg differential analysis, and hope to help you.
Although called "Perl-compatible regular Expressions", PHP is still a bit different from Perl's regular expressions, such as the modifier "G", which represents all matches in Perl, but does not include support for this modifier in PHP.
An analysis of ereg regular expressions in PHP:
There is the difference between the Ereg series functions, Ereg is also the regular expression function provided in PHP, but compared with preg, it is much weaker.
1, Ereg inside is not necessary and can not use separators and modifiers, so ereg function than preg to a lot weaker.
2, about "." : The point in the regular is usually all characters except the newline character, but in the Ereg "." Is any character, which includes line breaks! If in Preg hope "." To include line breaks, you can add "s" to the modifier.
3, ereg default use greedy mode, and can not be modified, this gives a lot of replacement and matching trouble.
4, Speed: This may be a lot of people are concerned about the problem, will not preg powerful is to exchange speed for? Do not worry, preg speed is far faster than Ereg, the author has done a program test:
Ereg Regular expression time test instance in PHP:
-
- Echo "Preg_replace used time:";
- $start = time ();
- for ($i=1; $i <=100000; $i ++) {
- $str = "Ssssssssssssssssssssssssssss" ;
- preg_replace ("/s/","",$str);
- }
- $ended = Time ()- $start ;
- Echo $ended;
- Echo "
- ereg_replace used time: ";
- $start = time ();
- for ($i=1; $i <=100000; $i ++) {
- $str = "Ssssssssssssssssssssssssssss" ;
- ereg_replace ("s","",$str);
- }
- $ended = Time ()- $start ;
- Echo $ended;
- Echo "
- Str_replace used time: ";
- $start = time ();
- for ($i=1; $i <=100000; $i ++) {
- $str = "Sssssssssssssssssssssssssssss" ;
- Str_replace ("s","",$str);
- }
- $ended = Time ()- $start ;
- Echo $ended;
- ?>
Ereg Regular Expression instance results in PHP:
- Preg_replace used Time:5
- ereg_replace used time:15
- Str_replace used Time:2
Str_replace because there is no need to match so very fast, and preg_replace faster than ereg_replace to a lot faster.
The contents of Ereg regular expressions in PHP are introduced here, which hopefully helps you understand and learn about Ereg regular expressions in PHP.
http://www.bkjia.com/PHPjc/446583.html www.bkjia.com true http://www.bkjia.com/PHPjc/446583.html techarticle We know Perl-compatible regular expressions in PHP, so what do we need to know about Ereg regular expressions? Here we are using Perl-compatible regular expressions and Perl/ereg to analyze the difference between ...