is written in front
The PHP regular delimiter used by Hy369 is slash (/, forward slash). I even thought that this was the only regular delimiter in PHP.
Hey, until today, I saw a rather strange example of using the # sign as a regular separator. Seeing this "strange" regular expression, I couldn't help but ask Du Niang. The result: I was stunned.
Really, until this moment, I realized that the regular separator under PHP is not actually only / .
Okay, let’s record this knowledge point that surprised Hy369.
PHP Regular expression delimiter
In PHP, the regular expression delimiter can be any character except: letters, numbers, backslashes, and whitespace characters.
Commonly used delimiters are: slash (/, forward slash), pound sign (#, hash sign) and tilde (~, tilde).
In other words, it can be the following patterns:
/test string/ #^[^0-9]Hy369$# +php blog+ %[A-Za-z0-9_-]%
Key points
If in a certain pattern, the delimiter in this pattern needs to be used in the regular expression , you need to add a backslash before this separator. For example:
/http:\/\//
In this case, the entire regular expression is not very intuitive. At this time, you can consider changing a delimiter to enhance the readability of the regular expression. Therefore, the above regular expression can be replaced by this:
#http://#
The above is the content of note 014 PHP regular expression delimiter. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!