匹配两个部分相同次数
我正在搜索代码来解析以下内容:
some texttext
我需要删除不必要的 出现,以便输出为:
some texttext
我编写了一个正则表达式,它执行了一次:
/[ ^<]*/i
如何在 和
上使此工作次数相同?
I'm searching for code to parse the following:
some texttext
I need to remove unnecessary <span>
occurrences, so that output is:
some texttext
I wrote a regex, which does this once:
/[^<]*</SPAN>/i
How do I make this work same number of times on both <span>
and </span>
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将适用于您的示例,但必须应用两次,因为它每次迭代都会删除一层嵌套
span
标记。因此,对于任意嵌套的标签,您需要为每个嵌套级别调用一次。
will work on your example, but it has to be applied twice because it removes one "layer" of nested
span
tags per iteration.So, with arbitrarily nested tags, you'd need to call this once for each level of nesting.
您可以尝试查看
后面是否直接跟着另一个
及其匹配的
直接前面加上另一个
。
但实际上您不能说该跨度毫无用处,因为可以将标记添加到这些特定跨度中。如果没有任何标记,那么最后剩余的跨度也毫无用处,也可能被删除。
You could try to see if a
<span>
is directly followed by another<span>
and its matching</span>
is directly prepended by another</span>
.But you cannot actually say that that span will be useless, because markup can be added to those specific spans. If there isn't any markup, the last remaining spans are useless as well and might just as well be removed too.