Home > Backend Development > PHP Tutorial > Explore PHP regular expression implementation information records_PHP tutorial

Explore PHP regular expression implementation information records_PHP tutorial

WBOY
Release: 2016-07-15 13:26:27
Original
831 people have browsed it

When we use PHP regular expressions, have we noticed how we operate when we need to record information? So here I will introduce to you the specific method of implementing information recording using PHP regular expressions. I hope it will be helpful to you.

In fact, in the process of developing PHP regular expressions, one of the characters is specially used to record information. This is the bracket "()". So how is such a magical function accomplished? What?

PHP regular expressions implement the parsing of information records:

In addition to user matching, PHP regular expressions can also use brackets "()" to record needs The information is stored and read by subsequent expressions.

PHP regular expression implementation information recording example and analysis:

<ol class="dp-c"><li class="alt"><span><span>/^([a-zA-Z0-9_-]+)@([a-zA-Z0-9_-]+)(.[a-zA-Z0-9_-])$/ </span></span></li></ol>
Copy after login

The above PHP regular expression implementation information recording example is to record the user name of the email address, and The server address of the email address (in the form of username@server.com or the like). If you want to read the recorded string later, you just need to use "escape character + recorded order" to read it. For example, "1" is equivalent to the first "[a-zA-Z0-9_-]+", "2" is equivalent to the second one ([a-zA-Z0-9_-]+), and "3" is The third one (.[a-zA-Z0-9_-]). But in PHP, "" is a special character that needs to be escaped, so "1" should be written as "\1" in the PHP expression.

In addition, we also pay attention to a PHP regular expression special symbol:

"|": The or symbol "|" is the same as the or in PHP, but it is a " |" instead of PHP's two "||"! This means that it can be a certain character or another string. For example, "/abcd|dcba/" may match "abcd" or "dcba".

This concludes the introduction to information recording using PHP regular expressions. I hope it will be helpful for you to understand and use PHP regular expressions.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446584.htmlTechArticleWhen we use PHP regular expressions, have we noticed how we operate when we need to record information? Woolen cloth? Then here is an introduction to PHP regular expression implementation information records...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template