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

Except for the syntax of the capturing group, other syntaxes are not verification of the capturing group_regular expression

微波
Release: 2017-06-28 13:41:44
Original
760 people have browsed it

这篇文章主要介绍了除捕获组的语法外,其它的(?...)语法都不是捕获组的验证,需要的朋友可以参考下

在一篇正则表达式技术文档中看到下面内容:

“外需要说明的一点是,除(Expression)和(?Expression)语法外,其它的(?...)语法都不是捕获组。”
这个内容是好理解的,但疑惑的是,该文章作者在另一篇相关正则的技术文章中,其中一个这样的实例,着实让我迷惑了一番:

文本内容

ab
Copy after login

正则表达式

(?is)(?:(?!).)*
Copy after login

注意上面正则表达式的代码,他对“(?!).”进行“强制非捕获组”,我在短信中告诉他,可以这样写:(?is)((?!).)*
两天仍未见他回复,于是在回过头来研究一下他代码,起初我将重点放在“(?!)”这个括号算不算捕获组。但是在看一次上面技术文章的代码我才反应过来。他不是针对(?!)强制为非捕获组,而是将(?!).强制为非捕获组,于是我就做了下面的测试:

文本内容

aa
Copy after login
Copy after login
Copy after login

正则表达式

((?!).)*(\1)*
Copy after login

匹配结果

aa
Copy after login
Copy after login
Copy after login

这就证明,如果不对“(?!).”进行强制为非捕获组,它是会捕获的,而这个捕获,我根本不需要它。
下面,我在测试一下,除了(Expression)和(?Expression)语法外,其它的,如环视,它算不算捕获组。

文本内容

aa
Copy after login
Copy after login
Copy after login

正则表达式

((?!).)*(\2.)*
Copy after login

匹配结果:不匹配
如有不同见解,欢迎讨论。

The above is the detailed content of Except for the syntax of the capturing group, other syntaxes are not verification of the capturing group_regular expression. 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!