在Velocity中使用Regex和ReplaceAll来提取文本

问题描述 投票:-1回答:1

在速度我有:

#set( $text = "#parse('file url')" )

我想要的是只提取div中名为“paragrafo-html”的文本。

文件内容和正则表达式在这里:

https://regex101.com/r/wr8H04/1

我写道:

$text.replaceAll('(?:.|\\n)*?<div class="paragrafo-html" style="">((?:.|\\n)*?)</div>(?:.|\\n)*', '$1')

但正如我所说的正则表达集团那样,它不起作用。

也:

$text.matches('(?:.|\n)*?<div class="paragrafo-html" style="">(?:.|\n)*?</div>(?:.|\n)*')

给我错误。

你能否告诉我在replaceAll中我做错了什么?

regex velocity
1个回答
0
投票

Wiktor Stribizew最后评论有效!所以:

$text.replaceAll('(?s).*?<div\s+class="paragrafo-html"\s+style="">(.*?)</div>.*', '$1')

谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.