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!