正则表达式匹配嵌套TAGS [英] Regular Expression matching nested TAGS

查看:95
本文介绍了正则表达式匹配嵌套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屋!

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