PHP Regular Expressions (PCRE)

Source: Internet
Author: User
Tags preg

PHP Regular Expressions (PCRE)

The regular expression (regular expression) describes a pattern of string matching that can be used to check whether a string contains a seed string, replaces a matched substring, or extracts a substring that matches a certain condition from a string.

For more regular expressions, refer to our: Regular Expressions-tutorials.

In PHP we can use the PCRE extension to match the pattern of strings.

PCRE function
function Description
Preg_filter Perform a regular expression search and replace
Preg_grep Returns an array entry for the matching pattern
Preg_last_error Returns the error code generated by the last Pcre regular execution
Preg_match_all Performs a global regular expression match
Preg_match Performs a regular expression match
Preg_quote Escaping regular expression characters
Preg_replace_callback_array Performs a regular expression search and replaces it with a callback
Preg_replace_callback Performs a regular expression search and replaces it with a callback
Preg_replace Perform a search and replace of a regular expression
Preg_split Separating strings with a regular expression
Preg Constants From
Constants Descriptionwhich version
PREG_PATTERN_ORDER The results are sorted according to "rules", only for Preg_match_all (), i.e. $matches[0] is the matching result of the complete rule, $matches [1] is the result of the first subgroup match, and so on. Since
PREG_SET_ORDER The results are sorted by "set" and used only for Preg_match_all (), or $matches[0] to hold all the results of the first match (including subgroups) information, $matches [1] to save the second result information, and so on.
PREG_OFFSET_CAPTURE View PREG_SPLIT_OFFSET_CAPTURE the description. 4.3.0
PREG_SPLIT_NO_EMPTY This tag tells Preg_split () to return to the non-empty part.
PREG_SPLIT_DELIM_CAPTURE This tag tells Preg_split () to capture what the parentheses expression matches. 4.0.5
PREG_SPLIT_OFFSET_CAPTURE If this flag is set, the offset of each occurrence of the matched substring is returned. Note that this changes the values in the returned array, each element is represented by the matching substring as the No. 0 element, and it is relative to the target string offset as an array of the 1th elements. This tag can only be used for preg_split (). 4.3.0
PREG_NO_ERROR Call Preg_last_error () returns when there is no matching error. 5.2.0
PREG_INTERNAL_ERROR If there is an pcre internal error, call Preg_last_error () is returned. 5.2.0
PREG_BACKTRACK_LIMIT_ERROR If the call backtracking limit is exceeded, the call to Preg_last_error () is returned. 5.2.0
PREG_RECURSION_LIMIT_ERROR If the recursion limit is exceeded, the call to Preg_last_error () is returned. 5.2.0
PREG_BAD_UTF8_ERROR If the last error is due to the exception of the Utf-8 data (only available under run in UTF-8 mode regular expressions). Causes the call to Preg_last_error () to return. 5.2.0
PREG_BAD_UTF8_OFFSET_ERROR If the offset does not match the valid Urf-8 code (only available under run in UTF-8 mode regular expression). Call Preg_last_error () to return. 5.3.0
PCRE_VERSION Pcre version number and release date (for example: "7.0 18-dec-2006"). 5.2.4

PHP Regular Expressions (PCRE)

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.