Regular expressions are a highly versatile technique in which almost all (or most) programming languages support regular expressions.
Introduction of regular expressions
What is a regular expression?
When writing a program or Web page that handles strings, there is often a need to find strings that match some of the complex rules. Regular expressions are the syntax used to describe these rules.
In determining the format of a user's e-mail address and the format of a mobile phone number
The main role is: segmentation, matching, find, replace
Regular expressions are a crucial point of knowledge for a programmer, so it's important for every programmer to learn the right things. Not only can we do some work that we can't do through the function, but it also helps us to reduce a lot of effort.
Perl-style Regular expression syntax
Pattern rule:/php/with two diagonal lines before and after the string
Matching function: the Preg_match () function searches for a pattern in a string, or returns a fake if there is a return true
Cases:
<?php
Header ("Content-type:text/html;charset=utf-8");
$mode = "/php/"; Rule pattern
$string = "I am studying PHP";
if (Preg_match ($mode, $string)) {
echo "matches successfully! ";
}else{
echo "does not match!" ";
}
?>
Elements in regular expressions
The regular expression contains three elements: Quantifiers, metacharacters, and modifiers
Order of operations in regular expressions
Follow the rules of operation from left to right, as shown in the following figure:
Url:http://www.bianceng.cn/webkf/php/201701/50525.htm