regex - Velocity 中的 Regex 和 ReplaceAll 提取文本
问题描述
在速度我有:
#set( $text = "#parse('file url')" )
我想要的是只提取名为“paragrafo-html”的 div 内的文本。
文件内容和正则表达式在这里:
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中做错了什么吗?
解决方案
Wiktor Stribizew 最后的评论有效!所以:
$text.replaceAll('(?s).*?<div\s+class="paragrafo-html"\s+style="">(.*?)</div>.*', '$1')
谢谢!
推荐阅读
- c# - IContainerBuilder.AddService 在添加 EdmModel 中的 IRouteBuilder OData .Net Core 中不起作用
- java - 按特定顺序合并两个地图
- javascript - 开发过程中 vs 代码扩展中的contributors.configuration 属性
- database - 使用时间范围在多个日志文件中搜索时间戳,但我有大量数据。那么,如何快速提取日志?
- python - 这是使用 tkinter 进行绘图的代码,但在我的课堂上使用激光方法会产生意想不到的结果
- bash - 将带有参数的 bash 命令传递给函数
- javascript - 在reactjs中迭代数组
- autohotkey - AHK 如果按下键,请执行此操作
- c - 如何对通用(void *)数组进行排序?
- java - 将第二个输入语句添加到代码后出错