The use of PHP regular expressions brings us a new feeling in actual development, so how do we master such a powerful tool? Let's take a look at the preliminary knowledge and understanding of PHP regular expression learning. I hope it will be helpful to you.
PHP is widely used in background CGI development of the Web, usually to obtain a certain result after user data. However, if the data entered by the user is incorrect, problems will occur, such as someone's Birthday is "February 30"! So how should we check whether the summer vacation is correct? The support of PHP regular expressions allows us to perform data matching very conveniently.
Some concepts related to PHP regular expressions:
Simply put, regular expressions are a powerful tool that can be used for pattern matching and replacement. Traces of regular expressions can be found in almost all software tools based on UNIX/LINUX systems, such as Perl or PHP scripting languages. In addition, JavaScript, a client-side scripting language, also provides support for regular expressions. Now regular expressions have become a common concept and tool and are widely used by various technical personnel.
There is something like this on a Linux website: "If you ask a Linux enthusiast what he likes most, he will probably answer regular expressions; if you ask him what he is most afraid of, besides tedious installation and configuration He will definitely talk about regular expressions. "
As mentioned above, regular expressions look very complicated and scary. Most PHP beginners will skip this and continue learning, but PHP The regular expressions in have powerful functions such as using pattern matching to find strings that meet conditions, determining whether strings meet conditions, or replacing qualified strings with specified strings. It would be a pity not to learn...
Basic syntax of PHP regular expressions:
A regular expression is divided into three parts: delimiter, expression and modifier.
The delimiter can be any character except special characters (such as "/!", etc.), and the commonly used delimiter is "/". The expression consists of some special characters (see special characters below) and non-special strings. For example, "[a-z0-9_-]+@[a-z0-9_-.]+" can match a simple electron Mail string. Modifiers are used to turn on or off certain functions/modes. The following is an example of a complete regular expression:
<ol class="dp-c"><li class="alt"><span><span>/hello.+?hello/is </span></span></li></ol>
The above regular expression "/" is the separator, the one between the two "/" is the expression, and the second "/" The following string "is" is the modifier.
If there is a delimiter in the expression, you need to use the escape symbol "", such as "/hello.+?/hello/is". In addition to being used as delimiters, escape symbols can also execute special characters. All special characters composed of letters need to be escaped with "", such as "d" representing all numbers.
This is where I introduce you to a little understanding of PHP regular expressions. I hope it will be helpful for you to understand and master PHP regular expressions.