Regular Expression string

Source: Internet
Author: User

[] In the string "[0-9] {15}" above is used to define optional characters, and {} is used to define the number of characters.

Besides [? -?] In addition to the definition, you can directly write acceptable characters. For example, [wjt98] indicates that

The control towel can only contain the "W", "J", "T", "9", and "8" characters.

In [], you can also use "^" to define the anti-set. For example, [^ A-SJ indicates other characters except "a"-"S ".

Both are acceptable.

{} Is used to define the number of characters. We have used a definition method above. In fact, {} has the following 5

Common formats:

The format {3} has already been used. It indicates that only three characters can be accepted, neither more nor less.

The format of {} indicates that 2-5 characters can be entered. For example, [0-9] {} indicates that 2 and 5 characters can be entered.

.

{N,} indicates that N to infinite characters can be accepted. For example, [A-Za-z {3,} indicates that at least three English characters must be entered in this column.

Characters.

The above describes the basic usage of the regularexpression attribute, but it cannot meet the requirements. If you want a table

If the value reaches any character, it cannot be expressed in []. In repularexpression, the character that expresses any character is "."

For example,. {1,} indicates that the string can be 1 to an infinite number of arbitrary characters.

Sometimes you need to use multiple-choice when using string expression rules, for example, either all are English characters,

Either it is a number, then we can use the "|" symbol, which is equivalent to the OR operator. For example, the [A-Za-Z] | [0-9] {3} table

If "|" appears in regularexpression, you can express it to avoid confusion in reading.

Formula is included in.

The above "[]", ".", "{}", "()", and "|" are all special symbols of regularexpression.

The accepted characters must be preceded by "\"

Comprehensive application of regularexpression

(1) Verify the email bar

{1 ,}@. {1 ,}\ .. {1 ,}

(2) Verify the telephone bar

(\ ([0-9] {0, 4} \) [0-9] {3, 15}) | ([0-9] (3, L 5) -[O-9] {}) | ([0-9] {11 })

(3) Verify the address bar

. {1 ,}( city | town | township). {1 ,}( road | street | road). {1 ,}. {0 .}

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.