Regular expression Tutorial: 30 minutes for you to master the regular expression syntax

Source: Internet
Author: User

The regular expression is not a programming language, and there is no function of computing and dealing with problems, it is a single string that describes or matches a series of strings that conform to a certain syntactic rule.


Examples of regular expression applications:

    • Prevent SQL injection: Especially for Web sites, security is critical, write good regular expressions, be able to verify input information, ensure the legitimacy of input data, not unscrupulous people invade the database to destroy the site.
    • Acquisition: Searching for the desired data from the Internet according to certain rules, regular expressions are a powerful tool for analyzing complex HTML tags.
    • Validating data: Data entered by the user needs to be validated and then submitted for security and desired data, both for the software and for the site.


Examples of common matches:

    • Match China phone number. Form: 0511-4405222 021-87888822 021-44055520-555 (0511) 4405222
    • Expression: "((d{3,4}) |d{3,4}-)? d{7,8} (-d{3}) *"
    • Match China postcode. Forms such as: 215421
    • Expression: "D{6}"
    • Match the e-mail. Forms such as: [email protected]
    • Expression: "w+ ([-+.] w+) *@w+ ([-.] w+) *.w+ ([-.] w+) * "
    • Matches a string consisting of 26 English letters.
    • Expression: "^[a-za-z]+$"
    • Match the URL.
    • Expression: @ "^[url]http://([/url][\w-]+\.) +[\w-]+ (/[\w-./?%&=]*)? "

Regular expression Tutorial: 30 minutes for you to master the regular expression syntax

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.