Example of basic regular expression usage in PHP getting started (regular expression matching, search, segmentation, etc)

Source: Internet
Author: User
This article mainly introduces the basic usage of regular expressions in the PHP Getting Started Tutorial, this paper analyzes the structure, principle, and related concepts and operation skills of regular expressions, such as regular expression matching, search, segmentation, element sub-operators, and modifiers, in combination with instance forms, for more information about PHP regular expressions, see the following example. We will share this with you for your reference. The details are as follows:

Demo1.php

 

Demo2.php

 

Demo3.php

 

Demo4.php

 

Demo5.php

 

Demo6.php

 

Demo7.php

 

Demo8.php

 Array ([0] => php5 [1] => php4) echo $ out [0] [0]; // php5?>

Demo9.php

 

Demo10.php

 

Demo11.php

 // Pay attention to one problem. [] brackets at this time are string brackets instead of syntax [a-z] //. it indicates matching any character. adding a "*" indicates matching zero or multiple characters. // brackets are divided into three groups. The first group is \ 1, and the second group is \ 2, the third group is \ 3 // currently only one group, \ 1 // The first problem. The first [B] matches the last [/B] and // solves the greedy match. $ Mode = '/(\ [B \]) (. *) (\ [\/B \])/U'; // U prohibits greedy $ replace ='\ 2'; $ String = 'This is a [B] php5 [/B], This is a [B] php6 [/B]'; // echo $ string; echo preg_replace ($ mode, $ replace, $ string);?>

Demo12.php

 OneStopWeb [1] ==> 163 [2] => com)?>

I hope this article will help you with PHP programming.


For more details about the basic usage of regular expressions (regular expression matching, search, segmentation, etc.) in PHP Getting Started Tutorial, please follow the PHP Chinese website!

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.