Application of Regular Expressions in network programming (1)

Source: Internet
Author: User
Tags valid email address

[Preface:] When writing a WEB program, we often judge the validity of a string, for example, whether a string is a number or a valid Email address. If you do not use a regular expression, the program will be very long and prone to errors. If you use a regular expression, it is easy to make these judgments. This topic describes the concept and format of a regular expression. The application examples in PHP and ASP are used to increase the reader's perceptual knowledge. Regular Expressions are widely used and need to be summarized continuously in learning and practice.
Introduction to Regular Expressions
In short, regular expressions are a powerful tool for pattern matching and replacement. It is widely used in network programming. Client scripting languages such as PHP or JavaScript and VBScript provide support for regular expressions. It can be seen that regular expressions have gone beyond the limits of a language or system and become widely accepted concepts and functions.
Regular Expressions allow users to construct matching modes by using a series of special characters, and then compare the matching modes with target objects such as data files, program input, and form input on the web page, execute the corresponding program based on whether the comparison object contains the matching mode.
For example, the most common application of regular expressions is to verify whether the format of the email address entered by the user online is correct. If the regular expression is used to verify that the format of the email address is correct, the form information entered by the user is processed normally. Otherwise, if the email address entered by the user does not match the regular expression mode, a prompt is displayed, ask the user to re-enter the correct email address. It can be seen that regular expressions play an important role in the logic judgment of WEB applications. We will give an example later.
Regular Expressions are generally in the form of/love/. The part between the "/" delimiters is the pattern to be matched in the target object. You only need to place the pattern content of the desired matching object between the "/" delimiters. Regular Expressions provide special "metacharacters" to allow users to customize mode content more flexibly ". Metacharacters are special characters that have special meanings in regular expressions. They can be used to specify the mode in which the leading character (that is, the character located before the metacharacters) appears in the target object. Frequently Used metacharacters include: "+ ,"*,? And {} ", or" s, S, d, w, and W. To allow users to set matching modes more flexibly, regular expressions allow users to use [] to define characters matching a certain range in the matching mode, instead of being limited to specific characters.
In addition to the above metacharacters, the regular expression also has another unique special character, that is, the positioning character. Specifies the position where the matching mode appears in the target object. Commonly used positioning symbols include: "^", "$", "", and "B ".

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.