简体   繁体   English

从html删除span标签

[英]Removing span tags from html

Can you help me with a code snippet (with/without regex) to remove all span tags from a string like this: (Silverlight - c#) 您能帮我用一个代码片段(带/不带正则表达式)从这样的字符串中删除所有span标签:(Silverlight-c#)

<a href="#">
  <span class="uiTooltipWrap bottom left leftbottom">
    <span class="uiTooltipText">
      dasd dssa<br />
      adsa sssss
    </span>
  </span>
</a>

Thanks. 谢谢。

HTMLAgilityPack is for you. HTMLAgilityPack适合您。

This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). 这是一个敏捷的HTML解析器,它构建了一个读/写DOM并支持纯XPATH或XSLT(您实际上不必了解XPATH或XSLT来使用它,不用担心...)。 It is a .NET code library that allows you to parse "out of the web" HTML files. 这是一个.NET代码库,可让您解析“网络外” HTML文件。 The parser is very tolerant with "real world" malformed HTML. 该解析器对“真实世界”格式的HTML十分宽容。 The object model is very similar to what proposes System.Xml, but for HTML documents (or streams). 对象模型与提出System.Xml的对象模型非常相似,但用于HTML文档(或流)。

In Perl we might say: 在Perl中,我们可能会说:

s/
  <     # tag opening character
  \/?   # optional slash
  span
  [^>]* # any non tag-closing characters
  >     # tag closing character
/
        # nothing
/x;

and I'm sure you can translate this into a C# regular expression. 并且我确定您可以将其转换为C#正则表达式。 Ie replace anything that matches </?span[^>]*> with nothing. 即,将与</?span[^>]*>匹配的所有内容替换为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM