Introduction to regular expressions in PHP development basic tutorial
1. Regular application scenarios
Matching email, mobile phone number, verification code
Replace sensitive keywords. For example: Collection of articles involving politics and swearing words
.
Early expression replacement technology, UBB file encoding, markdown editor replacement, etc.
In the future, you will also need to use regular expressions when writing your own template engines Show
Others...
2. Delimiters of regular expressions
Let’s learn Let’s take a look at the regular delimiter. The so-called delimiter is to set a boundary, and what is within the boundary is the regular expression.
The regulations of PHP's regular expression delimiters are as follows:
delimiter, a-zA-Z0-9\ cannot be used, and others can be used. They must appear in pairs, with a beginning and an end.
Let’s take a look at a few examples
Note: \ is an escape character, if you need to match it in the regular expression later /, as follows:
/ / /
If you really want to match / at this time, you need to convert the / in the delimiter Escape the free characters and write it as the following example:
/ \/ /
If you find it troublesome, you need to convert When defining characters, you can delimit the two forward slashes (/ /) and change them to other delimiters (# #)