选择2个评论标签之间的所有文本的最佳方法是什么?例如
<!-- Text 1
Text 2
Text 3
-->
Run Code Online (Sandbox Code Playgroud)
<\!--.*将捕获<!-- Text 1但不是Text 2,Text 3或-->
编辑
根据Basti M的回答,<\!--((?:.*\n)*)-->将选择第一个 <!--和最后一个 之间的所有内容-->.即下面的第1到11行.
我如何修改它以仅选择单独标签中的行?即第1至4行:
1 <!-- Text 1 //First
2 Text 2
3 Text 3
4 -->
5
6 More text
7
8 <!-- Text 4
9 Text 5
10 Text 6
11 --> //Last
Run Code Online (Sandbox Code Playgroud)
Bas*_*i M 11
根据您的底层引擎使用s-modifier(并-->在表达式的末尾添加.
这将使.匹配换行符也是如此.
如果s您无法使用-flag,则可以使用
<!--((?:.*\r?\n?)*)-->
Run Code Online (Sandbox Code Playgroud)
说明:
<!-- #start of comment
( #start of capturing group
(?: #start of non-capturing group
.*\r?\n? #match every character including a line-break
)* #end of non-capturing group, repeated between zero and unlimited times
) #end of capturing group
--> #end of comment
Run Code Online (Sandbox Code Playgroud)
要匹配您可以使用的多个注释块
/(?:<!--((?:.*?\r?\n?)*)-->)+/g
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11225 次 |
| 最近记录: |