Next: Regular expression (regex) Error usage causes a feature vulnerability, we continue to comb, regular expression error use, resulting in functional design vulnerabilities (bugs), do the web, need to master a lot of knowledge, web development this work, in the domestic also more than 10 years, many developers, are through: training ( self-study)-> imitate-> do project, such a process. Many of them have changed and become web development engineers. This line of entry is low and easy to get started. But it's not easy to be a master. Need to learn, master the knowledge of dozens of doors. And for just getting started with people, many times because of lack of systematic learning, theoretical support. It's a bit of a lift. Therefore, the emergence of these more or less functional design vulnerabilities, is very common!
Well, some digress, in the code to go to check, such vulnerabilities are often present. Let's look at the following code:
<?php
$user = "bcd123 John";
Match the user name in the beginning of ABC and BCD, followed by the numeric character
Preg_match_all ("/abc|bcd\d+/", $user, $match);
Var_dump ($match);
/* result is
Array (1) {
[0]=>
Array (1) {
[0]=>
string (6) ' bcd123 '
}
}}
Finds all pages appear with ABC or BCD beginning, followed by a numeric string. Through the above, we see that the correct match to bcd123, if we enter: $user = "abc123 John", the discovery cannot match. The reason is "|" Character, the lowest priority, the above writing will be: matching ABC or bcd\d+ string.
The above diagram, which will | be included in the ().
If you want to raise the priority, you can (ABC|BCD) \d+, match all the ABC or BCD strings, and follow the numbers immediately. In the use of "|" String, note that it has a low priority level and can be placed in () if you want to match the priority.