Home  >  Article  >  Web Front-end  >  What are the usage categories of comments in regular expressions?

What are the usage categories of comments in regular expressions?

php中世界最好的语言
php中世界最好的语言Original
2018-06-09 14:25:521595browse

This time I will bring you what are the usage categories of comments in regular expressions, and what are the precautions for using comments in regular expressions. The following is a practical case, let's take a look.

Another use of parentheses is to include comments via the syntax (?#comment).

For example: 2[0-4]\d(?#200-249)|25[0-5](?#250-255)|[01]?\d\d? (?#0-199).

If you want to include comments, it is best to enable the "Ignore whitespace characters in pattern" option, so that you can add spaces, tabs, and newlines arbitrarily when writing expressions, but these will be ignored when actually used. . When this option is enabled, all text following # to the end of the line will be ignored as comments. For example, we can write the previous expression like this:

(?<= # Assert the prefix of the text to be matched
<(\w )> # Find the letters enclosed by angle brackets or numbers (i.e. HTML/XML tags)
) # End of prefix
.* # Match any text
(?= # Assert the suffix of the text to be matched
<\/\1> # Find the content enclosed in angle brackets: preceded by a "/", followed by the previously captured tag

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Encapsulate Vue2 routing navigation hook and use it in actual combat

vue to make a verification code button countdown

The above is the detailed content of What are the usage categories of comments in regular expressions?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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