Operation instance of the PHPpregmatch regular expression function

Source: Internet
Author: User
In php, the preg_match () function is a common function used to execute regular expressions. This article describes the operation example of the PHPpregmatch regular expression function. For more information, see the preg_match () function in php. Regular expressions are used in almost all programming languages. this example introduces the application of the regular expression preg_match function in php.

The preg_match () function is used for regular expression matching. if the regular expression matches successfully, 1 is returned. otherwise, 0 is returned.

After a successful preg_match () match, the match is stopped. to match all the results, use the preg_match_all () function.

Syntax:

preg_match (pattern , subject, matches)

This instance matches strings with. and spaces after uppercase letters, and can only match J., because after a successful preg_match () match, the match will be stopped and will not be matched later.

 

Output result:

Array ([0] => J .)

The following describes the length of the preg_match string.

Preg_match: the regular expression extracts the target content. if there is a problem with whether the content is live or not, the code is dead.

Later, I suspect that PHP's preg_match has a string length limit, and found that the value of "pcre. backtrack_limit" is set to only 100000 by default.

Solution:

ini_set('pcre.backtrack_limit', 999999999);

Note: this parameter is available after php 5.2.0.

For more information, see pcre. recursion_limit.

Pcre. recursion_limit is the recursive limitation of PCRE. if this item is set to a large value, it will consume the available stacks of all processes and eventually cause PHP to crash.

You can also modify the configuration to limit the following:

Ini_set ('pcre. recursion_limit ', 99999 );

In actual project applications, it is best to set the memory limit: ini_set ('memory _ limit ', '64m');, which makes it safer.

For more articles on operating instances of PHP preg match regular expression functions, refer to PHP Chinese network!

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.