Regular Expression 1-PHP source code

Source: Internet
Author: User
Ec (2); 4. per regular function & nbsp; 1. preg_grep Function & nbsp; preg_grep (pattern, arrayinput); & nbsp; search for the matching pattern string in the input array input, and return all matching strings. The returned value is the matching string script ec (2) and script

4. per regular function
1. preg_grep Function
Preg_grep (pattern, array input );
Search for the matching pattern string in the input array input, and return all matching strings. The returned value is an array composed of all matching strings.
2. preg_match Function
Preg_match (pattern, string subject, [array matches])
This function searches for a string that matches pattern in the subject string. If yes, a non-zero value is returned. Otherwise, a zero value is returned. If matches is selected, the matched string will be placed at the first element and can be read using $ matches [0, the matching results of parentheses are also placed in this array in order. The first is $ matches [1], the second is $ matches [2], and so on.
3. preg_match_all Function
Preg_match_all (pattern, subject, array matches, [int order])
This function is used to search for non-overlapping texts matching the pattern in the subject string. If the matching text is found, the number of matched texts is returned. Otherwise, 0 is returned. The matched text is placed in the two-dimensional array matches. matches [0] stores all matching strings. The matching results of various embedded sub-modes are sequentially placed in the array matches [1] ~ [N.
The order parameter is optional. The optional values are PREG_PATTERN_ORDER and PREG_SET_ORDER.
4. preg_replace Function
Preg_replace (pattern, replacement, subject, [int limit])
This function replaces the pattern-compliant part of the subject with replacement. The return value type is the same as that of the subject type. If there is a replacement, the replaced value is returned. Otherwise, the original value is returned.
The parameter can be an array or a variable. There are several situations:
<1> If the subject parameter is of the array type. The function replaces each array element;
<2> If pattern is an array, the function replaces the pattern based on the Type in each pattern;
<3> if both pattern and replacement are arrays, replace them according to the elements in the two arrays;
<4> if the number of elements in replacement is less than that in pattern. Then the insufficient part will be replaced by a null string.
5. preg_split Function
Preg_split (pattern, subject, [int limit] [flages])
This function separates the subject string into several parts using the pattern defined by pattern, and returns an array containing the separated strings. Limit can limit the number of returned strings. If it is set to-1, no limit is imposed on the number of returned strings. Flags is also optional and has two values: PREG_SPLIT_NO_EMPTY. The set function does not return an empty string, PERG_SPLIT_DELIM_CAPTURE. This option sets the embedding sub-mode in pattern to be matched by the function.

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.