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