Phppcre regular expression full tutorial (1/3)-PHP source code

Source: Internet
Author: User
Tags expression engine
Ec (2); php tutorial pcre regular expression full tutorial pre-defined constant preg_pattern_order results sorted by & rdquo; rule & rdquo;, used only for preg_match_all, that is, $ matches [0] is the matching result of the complete rule, and $ matches [1] is the result of the first sub-group match preg_set_order: The result is sorted by & rdquo; set & rdquo, only used for preg_match _ script ec (2); script

Php tutorial pcre regular expression full tutorial
Predefined Constants

Preg_pattern_order

The results are sorted by the "Rules" and used only for preg_match_all. That is, $ matches [0] is the matching result of the complete rule, and $ matches [1] is the matching result of the first subgroup.
Preg_set_order:

The results are sorted by "set" and used only for preg_match_all. That is, $ matches [0] stores all results (including sub-groups) of the First matching result, $ matches [1] saves the second result information
Preg_offset_capture

The captured result contains not only the result substring, but also the position of the substring in the original string.
Preg_split_no_empty

Inform preg_split that only non-null parts are returned
Preg_split_delim_capture

Inform preg_split to capture the Matching content of the parentheses expression in the rule at the same time
Preg_split_offset_capture

If this mark is set, the offset position of each matching result will be returned at the same time.
Preg_no_error

If this value is returned after preg_last_error is called, it indicates that the regular expression is correct.
Preg_internal_error

If this value is returned after preg_last_error is called, an internal pcre error occurs.
Preg_backtrack_limit_error

If the number of backtracking times exceeds the preset value, the preg_last_error function returns this value.
Preg_recursion_limit_error

If the number of recursion times exceeds the preset value, the preg_last_error function returns this value.
Preg_bad_utf8_error

If the last error of preg is caused by abnormal UTF-8 data (only when the regular expression in UTF-8 mode is run), preg_last_error returns this value.

Preg_bad_utf8_offset_error

If the offset does not match the start point of the valid UTF-8 code (only when the regular expression in the UTF-8 mode is run), the value of preg_last_error is returned.
Pcre_version

Returns the pcre version number and release date.

Pattern Modifier

I pcre_classes
Case-insensitive Modifier
M pcre_multiline
Multi-row matching. By default, pcre considers the target string to be a group of single-row characters (however, it may actually contain multiple rows ). metacharacters ^ match only the start position of the string, while metacharacters $ match only the end of the string or before the new line (unless the d modifier is set ). this modifier keeps working with perl. After it is used, ^ and $ match the beginning and end of each row.
If the target string does not contain n characters or the ^ and $ characters are not displayed in the mode, setting this modifier will not affect you.
S pcre_dotall
Used to enhance the character class. (DOT) function. By default, the dot matches any character, but does not include line breaks or subsequent content. After this modifier is used, any character including line breaks can be matched.
X pcre_extended
If this modifier is set, white space characters in the mode are ignored unless escaped or in a character class. the content between an unescaped # And the next line break will be ignored by the Regular Expression Engine for convenience of adding comments.
E preg_replace_eval
After this modifier is used, the $ replacement parameter of preg_replace can not only use normal reverse references to obtain matching values, but also write the strings allowed by the eval syntax to evaluate values, the returned results are used for final replacement.
A pcre_anchored
If this modifier is set, the mode is forced to be "anchored" (anchored), that is, the constraint keeps it from the beginning of the string's mouth. this effect can also be achieved by constructing appropriate rules (perl can only achieve this)
D pcre_dollar_endonly
If this modifier is set, $ matches the end of the target string. If this modifier is not set, if the last character of the target string is a line break, $ will match the line break, not before the end of the string.
If the m modifier is set, the modifier is ignored. This is inconsistent with perl.
S
When a mode needs to be used multiple times, it is worth some time to analyze it for higher matching efficiency. if this modifier is set, this additional analysis will be performed. currently, this analysis of a pattern is only applicable to non-anchor matching (that is, there is no single fixed start character)
U pcre_ungreedy
This modifier reverses the greedy mode. Without this setting, the regular expression is greedy by default, and the quantifiers are added later? The pattern is not greedy, but if this modifier is set, the opposite is true.
This rule is incompatible with perl.
Can it be used in the mode? U to achieve the same effect
X pcre_extra
This modifier enables additional features that are not compatible with perl in a pcre. any backslash followed by a character with no special meaning will lead to an error, so as to retain these combinations for later extension.
By default, like perl, a backslash is followed by a character with no special meaning and will be interpreted as the original meaning of the character.
No other features are currently controlled by this Modifier
J pcre_info_jchanged
And internal options? J is the same, used to change the local pcre_dupnames option. The sub-group can have duplicate names.
U pcre8
This modifier opens an additional feature that is incompatible with perl in a pcre. The pattern string is considered UTF-8.

Homepage 1 2 3 last

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.