Regular Expression format

Source: Internet
Author: User
Tags ereg

Regular expressions are used in PHP to process complex text strings. Functions that support regular expressions include:
Ereg ()
Ereg replace ()
Eregi replace ()
Split ()
These functions use regular expressions as their first parameter. PHP uses POSIX Extension Rule expressions (using POSIX 1003.2 ). For all the descriptions about POSIX Extension Rule expressions, see the regex man page included in the PHP release.
Example 2-4. Regular expression examples
Ereg ("abc", $ string );
/* Returns true if "abc"
Is found anywhere in $ string .*/
Ereg ("^ abc", $ string );
/* Returns true if "abc"
Is found at the beginning of $ string .*/
Ereg ("abc $", $ string );
/* Returns true if "abc"
Is found at the end of $ string .*/
Eregi ("(ozilla. [23] | MSIE.3)", $ HTTP_USER_AGENT );
/* Returns true if client browser
Is Netscape 2, 3 or MSIE 3 .*/
Ereg ("([[: alnum:] +) ([[: alnum:] +) ([[: alnum:] + )",
$ String, $ regs );
/* Places three space separated words
Into $ regs [1], $ regs [2] and $ regs [3]. */


Ereg_replace ("^ ","
", $ String );
/* Put
Tag at the beginning of $ string .*/
Ereg_replace ("$ ","
", $ String );
/* Put
Tag at the end of $ string .*/
Ereg_replace ("", "", $ string );
/* Get rid of any carriage return
Characters in $ string .*/

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.