PHP PCRE
PHP Regular Expression (PCRE)
Regular expression (regular expression) describes a string matching pattern that can be used to check a Whether the string contains a certain substring, replacing the matching substring, or extracting a substring that meets a certain condition from a string, etc.
For more information on regular expressions, please refer to our: Regular Expressions - Tutorial.
In PHP we can use the PCRE extension to match string patterns.
PCRE function
Description | |||||||||||||||||||||||||||||||||||||||||||
Perform a regular expression search and replace | |||||||||||||||||||||||||||||||||||||||||||
Return matches Pattern array entry | |||||||||||||||||||||||||||||||||||||||||||
Returns the error code generated by the last PCRE regular execution | |||||||||||||||||||||||||||||||||||||||||||
Perform a global regular expression match | |||||||||||||||||||||||||||||||||||||||||||
Perform a regular expression match | |||||||||||||||||||||||||||||||||||||||||||
Escape regular expression characters | |||||||||||||||||||||||||||||||||||||||||||
Performs a regular expression search and replaces with a callback | |||||||||||||||||||||||||||||||||||||||||||
Performs a regular expression search and replaces using a callback | |||||||||||||||||||||||||||||||||||||||||||
| preg_split | ||||||||||||||||||||||||||||||||||||||||||
Separate strings by a regular expression |
Constant | Description | From which version |
PREG_PATTERN_ORDER | The results are sorted according to "rules" and are only used for preg_match_all(), that is, $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", only used for preg_match_all(), that is, $matches[ 0] saves all results (including subgroups) information of the first matching result, $matches[1] saves the second result information, and so on. | |
PREG_OFFSET_CAPTURE | View the description of PREG_SPLIT_OFFSET_CAPTURE. | 4.3.0 |
PREG_SPLIT_NO_EMPTY | This flag tells preg_split() to return the non-empty part. | |
PREG_SPLIT_DELIM_CAPTURE | This tag tells preg_split() to also capture bracket expressions matched to Content. | 4.0.5 |
PREG_SPLIT_OFFSET_CAPTURE | If this tag is set, the matching substring will appear each time The offset of is also returned. Note that this will change the value in the returned array so that each element is an array consisting of the matched substring as the 0th element and its offset relative to the target string as the 1st element. This flag can only be used with preg_split(). | 4.3.0 |
PREG_NO_ERROR | Call preg_last_error() to return when there is no matching error. | 5.2.0 |
PREG_INTERNAL_ERROR | If there is an internal PCRE error, call preg_last_error() to return. | ##5.2.0|
If the callback limit is exceeded, returned when calling preg_last_error(). | ||
If the recursion limit is exceeded, returned when preg_last_error() is called. | ||
If the last error is due to abnormal utf-8 data ( Available only when running regular expressions in UTF-8 mode). Caused by calling preg_last_error() to return. | ||
If the offset does not match a legal urf-8 code (Only available when running regular expressions in UTF-8 mode). Call preg_last_error() to return. | ||
PCRE version number and release date (for example: "7.0 18- Dec-2006"). |