正则表达式匹配嵌套TAGS [英] Regular Expression matching nested TAGS
问题描述
您好,我正在尝试匹配多嵌套引号的blockquotes并将其转换回BBCode 就正则表达式而言,这就是我所得到的 将其转换回html实体以在stackedoverflow上看到
([\ s \ S] *?)
([\ s \ S] *?) (?:
){2,})
我正在尝试匹配
报价
外部报价是这个报价
内部报价是这个
生成此
[quote]外部报价为 这[quote]内部报价是 这个[/quote] [/quote]
为此,我正在使用VBScript 5.5 Regeular Expressions. (但这并不重要)
我真的需要表达帮助.我已经为此使用HTML解析器感到厌倦,但是事实证明,使用正则表达式
会更困难解决方案好,这就是解析器所要做的全部事情.
这是伪代码.我不知道您的解析器,所以这是我能提供的最好的解析器.
首先找到带有quoteheader类的div标签.获取下一个兄弟姐妹.
那是blockquote标签.我们将此标签称为theQuote.
获取TheQuote的第一个孩子.这将是一个html文本项.那是外面的报价.
获取TheQuote的第三个孩子.这将是另一个blockquote标签.我们将此标签称为theInner.
获取内部的第一个孩子.这将是一个html文本项.那是内在的报价.
Hello I'm trying to match multi-nested quote's blockquotes and transform them back into BBCode This is what I got so far as far as regex is involved Converted it back to html entities to be seen on stackedoverflow
<div class="quoteheader"><div class="topslice_quote">([\s\S]*?)</div></div><blockquote>([\s\S]*?)(?:</blockquote><div class="quotefooter"><div class="botslice_quote"></div></div>){2,})
I'm trying to match this
<div class="quoteheader"><div class="topslice_quote">Quote</div></div><blockquote>Outside quote is this <div class="quoteheader"><div class="topslice_quote">Quote</div></div><blockquote>Inner quote is this</blockquote><div class="quotefooter"><div class="botslice_quote"></div></div> </blockquote><div class="quotefooter"><div class="botslice_quote"></div></div>
to generate this
[quote]Outside quote is this[quote]Inner quote is this[/quote][/quote]
I'm using VBScript 5.5 Regeular Expressions for this. (but this isn't that important)
I really need help on the expression. I've tired using a HTML Parser for this but it turns out to be more difficult then using regex
解决方案Well, this is all you need to do with the parser.
Here's the pseudocode. I don't know your parser so this is the best I can offer.
First find the div tag with the quoteheader class. Get the next sibling.
That is the blockquote tag. Let's call this tag theQuote.
Get the first child of theQuote. It will be a html text item. That is the outer quote.
Get the third child of theQuote. It will be another blockquote tag. Let's call this tag theInner.
Get the first child of theInner. It will be a html text item. That is the inner quote.
这篇关于正则表达式匹配嵌套TAGS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
相关文章
- 正则表达式匹配外部嵌套标签;
- Perl 正则表达式:匹配嵌套括号;
- Perl正则表达式:匹配嵌套括号;
- 正则表达式匹配:;
- 正则表达式 - 匹配;
- 正则表达式匹配;
- 正则表达式匹配#;
- 正则表达式匹配嵌套的json对象;
- 匹配嵌套大括号的正则表达式;
- 如何使用正则表达式匹配嵌套括号?;
- php - 如何用正则表达式匹配正则表达式?;
- 匹配有效正则表达式的正则表达式;
- 正则表达式 - javascript 正则匹配;
- 正则表达式匹配单个新行。正则表达式匹配双新线;
- JavaScript正则表达式-null参数使正则表达式匹配;
- 正则表达式正则表达式;
- 正则表达式匹配EOF;
- 正则表达式匹配次数;
- 正则表达式 VBA 匹配;
- If Else 正则表达式匹配;
- 正则表达式匹配 12345;
- 提取正则表达式匹配;
- 正则表达式和匹配;
- 正则表达式匹配太多;
- 重叠正则表达式匹配;
其他开发最新文章
- 拒绝显示一个框架,因为它将'X-Frame-Options'设置为'sameorigin';
- 什么是&QUOT; AW&QUOT;在部分标志属性是什么意思?;
- 在运行npm install命令时获取'npm WARN弃用'警告;
- cmake无法找到openssl;
- 从Spark的scala中的* .tar.gz压缩文件中读取HDF5文件;
- Twitter :: Error :: Forbidden - 无法验证您的凭据;
- 我什么时候需要一个fb:app_id或者fb:admins?;
- 将.db文件导入R;
- npm通知创建一个lockfile作为package-lock.json。你应该提交这个文件;
- 拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“script-src'self'”;