$zz = '/[0-5]\w+/'; What is the + sign used for? Why is it not included in some of the examples below?
益伦
益伦 2017-10-21 12:04:43
0
3
1641

<?php


$zz = '/[0-5]\w /';



##$string = '1C';

$string2 = '1C$';


##if(preg_match ($zz, $string, $matches)){

echo 'Matched, the result is:';

var_dump($matches);

}else{

echo 'No match';

}

##?>

Q1:$zz = '/ [0-5]\w /'; What is this number used for? Why is it not included in some examples later?

Q2: Why is the $string output result 1C? Shouldn't it be "1"?

Q3: If the output result of $string is 1C, shouldn’t the output result of $string1 be “1C$”?

益伦
益伦

reply all(3)
路过

[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

寻觅 beyond

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+\$/';

寻觅 beyond

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template