Branching--Regular expressions

Source: Internet
Author: User

Branching refers to the formulation of several rules, which, if any of these rules are met, are considered successful matches. Specifically, it's used | The symbols separate the various rules, and the conditions match from left to right. Tips

As a result of branching rules, as long as the match is successful, the following conditions will no longer match, so if you want to match the contents of the containing relationship, please pay attention to the order of the rules.

Here is an example of using a branch.

The rule for the U.S. ZIP Code is 5 digits or 5 digits connected to 4 digits, such as 12345 or 54321-1234, if you want to match all the zip codes, the correct regular expression is:

\D{5}-\D{4}|\D{5}
//Error writing
\d{5}|\d{5}-\d{4}

The following error notation can only match 5 digits and 9 digits of the first 5 digits of the case, and can not match 9-digit zip code.

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.