正则表达式匹配非单行且跨多行扩展的结果
我想更改/< \?php \ s([\ s \ s]*?)\?>/gi
单行PHP标签被排除在外的方式。
例如,在这里我只想匹配第二个PHP标签,而不是第一个标签:
Test number <?PHP echo($a);?> is here.
This is test number <?PHP echo($b);
$b = $a?> that expanded across multiple lines.
I want to change /<\?php\s([\s\S]*?)\?>/gi
the way that single line PHP tags become excluded.
For example, here I want to match only second PHP tag and not the first one:
Test number <?PHP echo($a);?> is here.
This is test number <?PHP echo($b);
$b = $a?> that expanded across multiple lines.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
多行
.
的变体:请参阅正则表达式演示 。 详细信息:
<\?php
- a子字符串
(?!\S)
- a右侧空白边界(紧邻右侧,必须有空白或字符串开头)((?:(?!<\?php(?!\S)|\?>).)*\R[\s\S]*?)
- 第 1 组:(?:(?!<\?php(?!\S)|\?>).)*
- 除换行符之外的任何单个字符,零个或多个并尽可能多地出现,不会启动?>` 字符序列
\R
- 换行序列[\s\S]*?
/(?s:.*?)
- 任何零个或多个尽可能少的字符\?>
code> -?>
子字符串。You can use
A variation with multiline
.
:See the regex demo. Details:
<\?php
- a<?php
substring(?!\S)
- a right-hand whitespace boundary (immediately to the right, there must be either a whitespace or start of string)((?:(?!<\?php(?!\S)|\?>).)*\R[\s\S]*?)
- Group 1:(?:(?!<\?php(?!\S)|\?>).)*
- any single char other than a line break char, zero or more and as many as possible occurrences, that does not start a<?php + a right-hand whitespace boundary or
?>` char sequence\R
- a line break sequence[\s\S]*?
/(?s:.*?)
- any zero or more chars as few as possible\?>
- a?>
substring.