English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
A regular expression (regular expression) describes a pattern of string matching that can be used to check if a string contains a certain substring, replace the matched substring, or extract a substring that meets certain conditions from a string, etc.
In PHP, we can use the PCRE extension to match string patterns.
Function | Description |
---|---|
preg_filter | Perform a search and replace with a regular expression |
preg_grep | Return the array entry of the matched pattern |
preg_last_error | Return the last error code generated by the PCRE regular expression execution |
preg_match_all | Perform a global regular expression match |
preg_match | Perform a regular expression match |
preg_quote | Escape regular expression characters |
preg_replace_callback_array | Perform a regular expression search and replace using a callback |
preg_replace_callback | Perform a regular expression search and replace using a callback |
preg_replace | Perform a search and replace with a regular expression |
preg_split | Split a string by a regular expression |
Constant | Description | From which version |
---|---|---|
PREG_PATTERN_ORDER | results are sorted by "rule", only for preg_match_all(), i.e., $matches[0] is the complete rule matching result, $matches[1] is the result of the first subgroup match, etc. | since |
PREG_SET_ORDER | results are sorted by "collection", only for preg_match_all(), i.e., $matches[0] saves all the result information of the first matching results (including subgroups), $matches[1save the result information of the second time, etc. | |
PREG_OFFSET_CAPTURE | ViewPREG_SPLIT_OFFSET_CAPTUREdescription. | 4.3.0 |
PREG_SPLIT_NO_EMPTY | this marker tells preg_split() to return non-empty parts. | |
PREG_SPLIT_DELIM_CAPTURE | this marker tells preg_split() to capture the content of bracket expressions at the same time. | 4.0.5 |
PREG_SPLIT_OFFSET_CAPTURE | if this marker is set, the offset of each match substring will also be returned. Note that this will change the values in the returned array, each element is a match substring as the 0th element, and its offset relative to the target string as the1an array of elements. This the marker can only be used for preg_split(). | 4.3.0 |
PREG_NO_ERROR | preg_last_error() is returned when there is no matching error. | 5.2.0 |
PREG_INTERNAL_ERROR | if there is an internal error in PCRE, preg_last_error() is returned. | 5.2.0 |
PREG_BACKTRACK_LIMIT_ERROR | if the backtracking limit exceeds, preg_last_error() is returned when called. | 5.2.0 |
PREG_RECURSION_LIMIT_ERROR | if the recursion limit exceeds, preg_last_error() is returned when called. | 5.2.0 |
PREG_BAD_UTF8_ERROR | if the last error is due to an abnormal utf-8data (only when running in UTF-8 available under the pattern regular expression). Caused by, called by preg_last_error(). | 5.2.0 |
PREG_BAD_UTF8_OFFSET_ERROR | if the offset is not equal to a valid urf-8code does not match (only when running in UTF-8 available under the pattern regular expression). Called by preg_last_error(). | 5.3.0 |
PCRE_VERSION | PCRE version number and release date (for example: ")7.0 18-Dec-2006"). | 5.2.4 |