正则表达式匹配嵌套TAGS

编程入门 行业动态 更新时间:2024-10-25 06:22:08
本文介绍了正则表达式匹配嵌套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

本文发布于:2023-10-27 19:00:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534265.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   正则表达式   TAGS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!