Home > Web Front-end > JS Tutorial > body text

What are the usage categories of comments in regular expressions?

php中世界最好的语言
Release: 2018-06-09 14:25:52
Original
1628 people have browsed it

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!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!