Regular Expression of javascript matching license plate number

Source: Internet
Author: User
Tags php regular expression

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

Related Article

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.