---------------------------------------------------------Regular Collection
Mobile Number:
$mode = "/^1[358]\d{9}/";
e-mail address:
$mode = "/^[a-z][-_\."? [A-z\d]*@[a-z0-9]+[\.] [A-z] {2,4}/i ";
----------------------------------------------------------Regular basis
$mode = "/^1[358]\d{9}/i";
The matching module must be in//start and end, and the second/post can add mode modifier
Atomic
①a-z A-Z _ 0-9//most common characters
② (ABC)//cell symbol enclosed in parentheses
③[ABCS] [^ABD]//The atomic table enclosed in square brackets,
The ^ in the atomic table represents the excluded or opposite content
\d contains all numbers [0-9]
\d except all numbers [^0-9]
\w contains all English characters [a-za-z_0-9]
\w except for all English characters [^a-za-z_0-9]
\s contains blank areas such as carriage return, line wrapping, paging, etc. [\f\n\r]
Metacharacters
* Match the previous content 0 times 1 or more times
+ 1 or more times
? 0 or 1 times
. Represents any one character (except for carriage return line wrapping)
| Quite with PHP's | | (Meaning of "or")
^ Force Match string Header content
$ force Match string trailing content
[^ABC] matches content other than a or B or C
\b Matches word boundaries, which can be spaces or special symbols
\b Matches anything other than a word boundary
{m} matches the previous content with a repeat number of M times
{m,} The number of repetitions of the previous content is greater than or equal to M times
{M,n} matches the number of repetitions of the previous content m times to N times
() whole match, and put into memory, can use \\1 or \\2 ... Get
Priority: decreasing in descending order
() parentheses because it is memory processing, so the highest
* ? + {} Repeat match content next
^ $ \b Border Processing third
| Condition Processing IV
Finally, the matching is calculated in order of operation
Common modifier: $mode = "/Regular/U";
I regular content is not case-sensitive at match time (by default it is differentiated)
M uses multi-line recognition matching when matching first content or tail content
S converts the carriage return to a space
x ignores whitespace in the regular
A Force A match from the beginning
D force $ match tail without any content \ n
U suppresses greedy matching, only tracks to the nearest match and ends,
Regular expressions commonly used in acquisition programs
Application
Preg_match_all (string pattern, string subject, array matches [, int flags])
Capture more detailed content, collect Web pages, analyze text
Preg_replace (mixed pattern, mixed replacement, mixed subject [, int limit])
Preg_replace (mixed pattern, mixed replacement, mixed subject [, int limit])
Tip 1, the replacement content can be a regular or an array regular
2, the replacement content can be replaced by the modifier e to resolve the content of the execution
Preg_split (string pattern, string subject [, int limit [, int flags]])
Using regular expressions to cut related content, similar to the previously learned explode cutting function, but explode
It can only be cut in one way with limitations.
-------------------------------------------------Debugging Code
[Code]
$mode = "/^[a-z][-_\."? [A-z\d]*@[a-z0-9]+[\.] [A-z] {2,4}/i ";
$str = "A12345@jb51.net";
echo $str. ";
if (Preg_match ($mode, $str, $arr)) {
Echo ' Succeed-'. $arr [0];
}else{
Echo ' failed ';
}
?>
[Code]
http://www.bkjia.com/PHPjc/322489.html www.bkjia.com true http://www.bkjia.com/PHPjc/322489.html techarticle ---------------------------------------------------------Regular Favorite mobile phone number: $mode = "/^1[358]\d{9}/"; e-mail address: $mode = "/^[ A-z][-_\.]? [A-z\d]*@[a-z0-9]+[\.] [A-z] {2 ...