Php5 and mysql5web development technology-5 regular expression _ PHP Tutorial

Source: Internet
Author: User
Tags ereg
Php5 and mysql5web development technical details-5 regular expressions. RegularExpression is a concise and flexible expression for searching and replacing string patterns. It is not difficult to understand the importance, but without some practice, Regular Expression is a concise and flexible Expression for searching and replacing string patterns.

It is not difficult to understand the importance. However, it is not easy to implement flexible applications without some practice.

In php, there are two types of regular expressions: POSIX and PCRE.

First, simply list the main content, and then add instructions and instances.

I. POSIX (Portable Operating System Implementation for Unix), which means Unix can be transplanted to the Operating System Implementation interface.

1. ^ and $ delimiters

2. quantifiers or qualified words

*

+

?

{N}

{N ,}

{N, m}

3. square brackets

[AAeEiIoOuU] character cluster of all vowel characters

[0-9] [a-z]

4. pre-defined character clusters (built-in generic character clusters, specifying the character processing range)

[[: Alpha:] uppercase and lowercase letters, same as [a-zA-Z]

[[: Digit:] number, same as [0-9]

[[: Alnum:] uppercase and lowercase letters and numbers, same as [a-zA-Z0-9]

[[: Cntrl:] control characters, including Tab, return, or backslash

[[: Space:] any white characters, including spaces, tabs, line breaks, page breaks, and carriage returns

......

Do not list them one by one

5. Regular Expression functions

Ereg (condition, <原始字符串> )

Eregi () is case insensitive

Ereg_replace (): added the character replacement function based on ereg ().

Eregi_replace ()

Split () splits the string into arrays based on the delimiter in the string

Spliti ()

SQL _regcase ()

6. POSIX submode

II. PCRE (Perl Compatible Regular Expression)

1. character clusters

\ B

\ D

\ S

\ T

\ W

2. matching

Delimiter/is used at the beginning and end of the expression. after the last separator/, you can add a modifier.

I, M, S, X, U, DU

You can also use a variety of metacharacters, similar to POSIX locators and character clusters.

\ A, \ B, \ B, \ d, \ D, \ s, \ S, [], (), ^, $,., \, \ w, \ W

3. function www.2cto.com

Preg_match ():

Example: preg_match ('/^ [[: alnum] {4, 8} $/', $ username)

Preg_match_all ()

Preg_quote (): add a conversion character

Preg_split ():

Preg_grep ()

Preg_replace (): Replace

Preg_replace_callback ()

Regular (Regular Expression) is a concise and flexible Expression for searching and replacing string modes. It is not difficult to understand the importance, but if there is no practice, do it...

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.