Understanding of PHP regular expressions _ PHP Tutorial

Source: Internet
Author: User
Tags email string php regular expression
A brief introduction to PHP regular expressions. The use of PHP regular expressions brings us a new feeling in actual development. how can we master such a powerful tool? Next let's take a look at the use of PHP regular expressions to learn PHP regular expressions, which has brought us a new feeling in actual development. how can we master such a powerful tool? Let's take a look at the preliminary knowledge of PHP regular expression learning and hope to help you.

PHP is widely used in Web background CGI development. it usually produces some results after user data. However, if the user input data is incorrect, a problem may occur, for example, a person's birthday is "August February 30 "! How can we check whether the summer vacation is correct? The support of PHP regular expressions allows us to easily perform data matching.

Some concepts related to PHP regular expressions:

In short, regular expressions are a powerful tool for pattern matching and replacement. Trace regular expressions in almost all UNIX/LINUX-based software tools, such as Perl or PHP scripting languages. In addition, the script language of the JavaScript client also provides support for regular expressions. now, regular expressions have become a common concept and tool and are widely used by various technical personnel.

On a Linux website, there is a saying like this: "If you ask Linux fans what they like most, he may answer regular expressions. if you ask him what he is most afraid, in addition to tedious installation configurations, he will definitely say regular expressions. "

As mentioned above, regular expressions seem very complex and scary. most PHP beginners will skip this section and continue the following learning, however, regular expressions in PHP can use pattern matching to find matching strings, determine whether a string meets the conditions, or use a specified string to replace matching strings, it's a pity that you don't study ......

Basic PHP regular expression syntax:

A regular expression is divided into three parts: separator, expression, and modifier.

Separators can be any character except special characters (for example "/! ", Etc.), the commonly used separator is "/". The expression is composed of special characters (see the following for special characters) and non-special strings, such as "[a-z0-9 _-] + @ [a-z0-9 _-.] + "can match a simple email string. Modifier is used to enable or disable a function/mode. The following is an example of a complete regular expression:

 
 
  1. /hello.+?hello/is

The above regular expression "/" is the separator, the expression is between two "/", and the string "is" after the second "/" is the modifier.

If the expression contains delimiters, you need to use the escape symbol "", such as "/hello. +? /Hello/is ". In addition to separators, escape symbols can also execute special characters. all special characters consisting of letters must be escaped by "". for example, "d" represents all numbers.

I will introduce you to some understanding of PHP regular expressions here, and hope to help you understand and master PHP regular expressions.


Why? Let's take a look at PHP regular expression learning...

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.