use of the PHP regular expression preg_match:
With Preg_match (), we can complete the rule matching of strings. If a match is found, the Preg_match () function returns 1, otherwise 0 is returned. There is also an optional third parameter that allows you to put a matching part in an array. This functionality can become very useful when validating data.
- $ string "Football";
- }
The above example will match successfully, because the word football contains foo. Now let's try a more complicated one, such as verifying an Email address.
- $ string "First.last@domain.uno.dos"
([.] [a-za-z0-9_]+) *[@][a-za-z0-9_]+ ([.]
This example verifies that the email address is in the correct format.
Rules for PHP Regular expression preg_match:
We will look at the various rules represented by this regular expression through the demonstration of the above example.
PCRE, as the name implies, has the same syntax as regular expressions in Perl, so each regular expression must have a pair of delimiters. We generally use/as delimiters.
Start with ^ and end of $ let PHP check from the beginning of the string to the end. If there is no $, the program will still match to the end of the Email.
[and] are used to restrict the type of license input. For example A-Z allows all lowercase letters, a-Z allows all uppercase letters, 0-9 all numbers, and more, among other types.
{and} are used to limit the number of characters expected. For example, {2,4} indicates that each section of a string can have a length of 2-4 characters, such as. com.cn or. Info. Here, "." does not count as a character, because the type of license input defined before {2,4} is only uppercase and lowercase, so the segment matches only the uppercase and lowercase letters
(and) are used to combine subsections and define the characters that must exist in the string. (A|b|c) to match A or B or C.
(.) will match all characters, while [.] Only matches "." itself.
To use some of the symbols themselves, one must be added first. These characters are: () []. * ? + ^ | $
PHP Regular expression Preg_match related content to introduce you here, I hope you understand and grasp the PHP preg_match regular expression helpful.
http://www.bkjia.com/PHPjc/446307.html www.bkjia.com true http://www.bkjia.com/PHPjc/446307.html techarticle PHP Regular Expression preg_match use: Using Preg_match (), we can complete the rule matching of the string. If a match is found, the Preg_match () function returns 1, otherwise 0 is returned. ...