如何使用正则表达式匹配多行? [英] How to match multiline using regex ?

查看:125
本文介绍了如何使用正则表达式匹配多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#{{< div class => {{Meth [#0#]}}< / div>}}#
< div class =form -group form-col-2>
#{{< div class =form-group-inline>
< label> {{ABCDEF}}< / label>
< div class =inpt>
{{?? DropList ??}}

{{?? DropList ??}}
< / div>
< / div>}}#
< / div>
< div class =form-group form-col-2>
#{{< div class =form-group-inline>
< label> {{DEFGHI}}< / label>
< div class =inpt>
{{?? DropList ??}}

{{?? DropList ??}}
< / div>
< / div>}}#
< / div>





我有什么尝试过:



i尝试了下面的表达但没有得到所有数学。

(?:\ #\ {\ {)(?:。*)(?:\} \} \#)$ 





我想要的是

1)

#{{< div class => {{Meth [#0#]}}< / div>}} #



2)

#{{< div class =form-group-inline> 
< label> {{ABCDEF}}< / label>
< div class =inpt>
{{?? DropList ??}}

{{?? DropList ??}}
< / div>
< / div>}}#



3)

#{{< div class =form-group-inline > 
< label> {{DEFGHI}}< / label>
< div class =inpt>
{{?? DropList ??}}

{{?? DropList ??}}
< / div>
< / div>}}#

解决方案





我想要的是

1)

#{{< div class => {{Meth [#0#]} }< / div>}}#<$ pre> 

2)

#{{< div class =form-group-inline> 
< label> {{ABCDEF}}< / label>
< div class =inpt>
{{?? DropList ??}}

{{?? DropList ??}}
< / div>
< / div>}}#



3)

#{{< div class =form-group-inline > 
< label> {{DEFGHI}}< / label>
< div class =inpt>
{{?? DropList ??}}

{{?? DropList ??}}
< / div>
< / div>}}#


了解正则表达式选项:RegexOptions.multiline

常规表达选项| Microsoft Docs [ ^ ]



只是一些有趣的链接,可以帮助构建和调试RegEx。

这是一个链接到RegEx文档:

perlre - perldoc.perl.org [ ^ ]

以下是帮助构建RegEx并调试它们的工具的链接:

.NET正则表达式测试程序 - 正则表达式风暴 [ ^ ]

Expresso正则表达式工具 [ ^ ]

RegExr:Learn,Build,&测试RegEx [ ^ ]

此节目RegEx是一个很好的图表,它非常有助于理解RegEx的作用:

Debuggex:在线可视正则表达式测试器。 JavaScript,Python和PCRE。 [ ^ ]


你的正则表达式似乎不对。正则表达式需要在#{和}#之间查找字符串。这是一个工作示例。



cp_How-to-match-multiline-using-regex [ ^ ]



参考:

RegEx表达式将捕获两个字符之间的所有内容,包括多行块 - Stack Overflow [ ^ ]


#{{<div class="">{{Meth[#0#]}}</div>}}#
<div class="form-group form-col-2">
	#{{<div class="form-group-inline">
		<label>{{ABCDEF}}</label>
		<div class="inpt">
		{{??DropList??}}
			
		{{??DropList??}}
		</div>
	</div>}}#                                        
</div>
<div class="form-group form-col-2">
	#{{<div class="form-group-inline">
		<label>{{DEFGHI}}</label>
		<div class="inpt">
		{{??DropList??}}
			
		{{??DropList??}}
		</div>
	</div>}}#                                       
</div>



What I have tried:

i tried following expression but not get all mathces.

(?:\#\{\{)(?:.*)(?:\}\}\#)$



what i want is
1)

#{{<div class="">{{Meth[#0#]}}</div>}}#


2)

#{{<div class="form-group-inline">
		<label>{{ABCDEF}}</label>
		<div class="inpt">
		{{??DropList??}}
			
		{{??DropList??}}
		</div>
	</div>}}# 


3)

#{{<div class="form-group-inline">
		<label>{{DEFGHI}}</label>
		<div class="inpt">
		{{??DropList??}}
			
		{{??DropList??}}
		</div>
	</div>}}#  

解决方案



what i want is
1)

#{{<div class="">{{Meth[#0#]}}</div>}}#


2)

#{{<div class="form-group-inline">
		<label>{{ABCDEF}}</label>
		<div class="inpt">
		{{??DropList??}}
			
		{{??DropList??}}
		</div>
	</div>}}# 


3)

#{{<div class="form-group-inline">
		<label>{{DEFGHI}}</label>
		<div class="inpt">
		{{??DropList??}}
			
		{{??DropList??}}
		</div>
	</div>}}#  


read about Regex options: RegexOptions.multiline
Regular Expression Options | Microsoft Docs[^]

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]


The regular expression you have doesn't seem right. The regular expression need to look for string in between #{ and }# . Here is a working example.

cp_How-to-match-multiline-using-regex[^]

Reference:
RegEx expression that will capture everything between two characters including multiline blocks - Stack Overflow[^]


这篇关于如何使用正则表达式匹配多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆