Matching characters such as:
Jing Z 12345-Jing Z12345
ZF 12345-zf12345
Temporary 12345 Temporary 12345
Rules:
First digit: Chinese or letter second: The letter or the Chinese third digit can be a space can not
followed by a letter or number 5-7
Final Result:
$str = "Jing-time 12345";
$RG = "/^[\x{4e00}-\x{9fa5}|a-za-z]{1}[\x{4e00}-\x{9fa5}|a-za-z]{1}[\s]{0,1}[0-9a-za-z]{5,7}$/u";
$match =preg_match ($RG, $STR);
Print_r ($match);
Output is 1
Optimized under
$RG = "/^[\x{4e00}-\x{9fa5}|a-za-z]{1}[\s]{0,1}[0-9a-za-z]{5,7}$/u";
which
\X{4E00}-\X{9FA5} is 16 binary matching Chinese
A-za-z Match Letter Case
[\s] {0,1} indicates a space of 1
[0-9a-za-z] {5,7} indicates 5-7 digits or letters
PHP Regular extension
1. Intercept a number from a string
$strs = "Option-model-1 wide-swatch ModelCode-8228646 selected hover";
$patterns = "/modelcode-(\d+)/I";
Preg_match_all ($patterns, $strs, $arr);
Print_r ($arr);