<?php
$zz = '/[0-5]\w /';
##if(preg_match ($zz, $string, $matches)){
echo 'Matched, the result is:';
var_dump($matches);
}else{
echo 'No match';
}
##?>
路过2017-10-21 22:24:59
[0-5] can match any one of 0-5
\w matches any word character including underscores. Equivalent to '[A-Za-z0-9_]'. $ is not in scope
+ identifies one or more times
寻觅 beyond2017-10-21 12:35:29
Because $, +, \, etc. are all special symbols, so when you want to match these characters, you must clearly indicate which special symbol you want to match in $pattern (use a backslash to transfer),
For example If you want to match $ in $string2, just change $zz = '/[0-5]\w+/'; to $zz = '/[0-5]\w+\$/';
寻觅 beyond2017-10-21 12:27:02
Q1, + means matching the previous atom appearing 1 or more times
Q2, see Q1, + means the previous \w (character) appears 1 or more times, so the C after 1 also Will be matched
Q3, $, +, - and other symbols are special symbols. I forgot where I read a blog. \w cannot match these special symbols. You can try changing $ to Other letters can be matched. As for the reason, if anyone passes by, I hope to explain it