Regular Expression of javascript matching license plate number
Matching characters include:
Jing Z 12345-jing Z12345
ZF 12345-ZF12345
Temporary 12345 temporary 12345
Rules:
First Digit: Chinese character or second digit: letter or Chinese character. Third digit can be a space.
Followed by 5-7 letters or numbers
Final result:
$ Str = "Beijing 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 );
The output result is 1.
Optimized
$ Rg = "/^ [\ x {4e00}-\ x {9fa5} | a-zA-Z] {1} [\ s] {0, 1} [0-9a-zA-Z] {5, 7} $/u ";
Where
\ X {4e00}-\ x {9fa5} is hexadecimal matching Chinese
A-zA-Z matches uppercase and lowercase letters
[\ S] {0, 1} indicates that the space is 1
[0-9a-zA-Z] {5, 7} indicates that 5-7 digits are numbers or letters.
Php Regular Expression Extension
1. extract 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 );