JavaScript matching license plate number regular expression

Source: Internet
Author: User


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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.