regex - 需要使用 html 对正则表达式进行更精细的调整
问题描述
我想做的是弄清楚如何使用正则表达式从 HTML 标记集合中提取最里面的项目。即:目标文本
Function FindInnerHtml(Work As String) As String
Dim Results As String, myRegExp, myMatches As Object, thisMatch As Object
Let myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = ">(.*?)<"
Set myMatches = myRegExp.Execute(Work)
If (myMatches.Count = 0) Then
Results = myMatches(0)
Results = Replace$(Replace$(Results, ">", ""), "<", "")
End If
FindInnerHtml = Results
End Function
我从函数中得到的是内部 HTML,即目标文本,我宁愿能够做的是确保我不需要添加双 replace$() 来清理结果。
解决方案
对于边缘情况,它很粗糙并且惨遭失败,但这样的事情可能会奏效:
<[a-zA-Z]{1}[a-zA-Z\d]*>([^><]*)</[a-zA-Z]{1}[a-zA-Z\d]*>
$1
将包含内部文本
推荐阅读
- javascript - 在这个代码片段中,为什么“this”最终绑定到窗口对象而不是数组 b?
- c# - 以 xamarin 形式将用于 MS DI 的 DryIoc 适配器添加到 Prism DryIoc
- node.js - 如何模拟在测试类中创建的 API 客户端?
- java - 如何将用户重定向到 playstore 以外的商店(huawei-store、oppo-store、9apps-store 等)?
- d - 使用 writeln 打印结构时额外的 null
- data-structures - 关于将答案中缀转换为后缀的困惑
- python - 为什么Regex finditer只返回第一个结果
- java - 为什么 org.ehcache.impl.internal.concurrent.ConcurrentHashMap.transfer 中的 ehcache 3.7.1 死锁
- r - 循环不从 r 中的 2 个不同文件返回列的所有对象的匹配值
- postgresql - Postgres Wire Protocol NoticeResponse 消息与文档不匹配