Regular expression (regular expression) describes a string matching pattern, which can be used to check whether a string contains a certain substring, replace the matching substring, or extract a substring that meets a certain condition from a certain string. wait.
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.
function | describe |
---|---|
preg_filter | Perform a regular expression search and replace |
preg_grep | Returns array entries matching pattern |
preg_last_error | Returns the error code generated by the last PCRE regular 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 regular expression search and replace |
preg_split | Separate strings by a regular expression |
constant | describe | Since which version |
---|---|---|
PREG_PATTERN_ORDER | The results are sorted by "rule", which is only used in preg_match_all(), that is, $matches[0] is the match result of the complete rule, $matches[1] is the result of the first subgroup match, etc. | since |
PREG_SET_ORDER | The results are sorted by "set", which is only used for preg_match_all(), that is, $matches[0] saves all the results (including subgroups) information of the first matching result, $matches[1] saves the second result information, etc. wait. | |
PREG_OFFSET_CAPTURE | See 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 flag tells preg_split() to also capture the content matched by the bracket expression. | 4.0.5 |
PREG_SPLIT_OFFSET_CAPTURE | If this flag is set, the offset of each occurrence of the matching substring will also be 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 | Returned by calling preg_last_error() when there are no matching errors. | 5.2.0 |
PREG_INTERNAL_ERROR | If there is an internal PCRE error, call preg_last_error() to return. | 5.2.0 |
PREG_BACKTRACK_LIMIT_ERROR | Returned when preg_last_error() is called if the callback limit is exceeded. | 5.2.0 |
PREG_RECURSION_LIMIT_ERROR | Returned when preg_last_error() is called if the recursion limit is exceeded. | 5.2.0 |
PREG_BAD_UTF8_ERROR | If the last error is due to unusual UTF-8 data (only available when running regular expressions in UTF-8 mode). Caused by calling preg_last_error() to return. | 5.2.0 |
PREG_BAD_UTF8_OFFSET_ERROR | If the offset does not match a valid urf-8 code (only available when running regular expressions in UTF-8 mode). 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 |