<p class="MsoNormal">
<span lang="EN-US">http://www.baidu.com<!--[if gte vml 1]><v:shape  id="_x0000_i1027" type="#_x0000_t75" alt="" style='width:19.5pt;height:15pt'>  <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image001.jpg"   o:href="../Local%20Settings/Temp/%7dB)O@27$~09%7b0VR%7b8FN%7d1HX.jpg"/> </v:shape><![endif]--><![if
!vml]><img width="26" height="20" src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image001.jpg"
v:shapes="_x0000_i1027"><![endif]></span></p>这是我从剪切板中获取的HTML格式化的RTF内容,现在要将非HTML标签从中踢除,正则表达式要怎么写?

解决方案 »

  1.   

    原字符串<p class="MsoNormal">
            <span lang="EN-US">http://www.baidu.com<!--[if gte vml 1]><v:shape  id="_x0000_i1027" type="#_x0000_t75" alt="" style='width:19.5pt;height:15pt'>  <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image001.jpg"   o:href="../Local%20Settings/Temp/%7dB)O@27$~09%7b0VR%7b8FN%7d1HX.jpg"/> </v:shape><![endif]--><![if
                !vml]><img width="26" height="20" src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image001.jpg"
                    v:shapes="_x0000_i1027"><![endif]></span></p>
    你想得到什么
      

  2.   

    <textarea id="htmlContent" cols="80" rows="10"></textarea>
    <input type="button" onclick="test()" value="test" />
    <script type="text/javascript">
        function test()
        {
            var tmp = document.getElementById("htmlContent").value;
            alert(getHTML(tmp));
        }
        function getHTML(html) {
            var div = document.createElement("div");
            div.innerHTML = html;
            return div.innerText;
        }
    </script>
      

  3.   

    原字符串应该是这样的。
    <p>...</p><span><o:f>....</o:f></span><otherHTML><o:other></o:other></otherHTML>
    现在想去掉<o:xxx .... />若是<o:xxx>....</o:xxx>
    就是想得到纯正的HTML。
      

  4.   

    想得到<p>... </p><span>  </span> 
    还是想得到<p>... </p><span>  </span> <otherHTML>  </otherHTML>
      

  5.   

    是想得到 <p>... </p> <span>  </span> <otherHTML>  </otherHTML>otherHTML是指其它HTML标签。
      

  6.   

    string str = "<p>... </p> <span> <o:f>.... </o:f> </span> <otherHTML> <o:other> </o:other> </otherHTML>";
                Regex reg = new Regex(@"(?is)<o:[^>]+>.*?</o:[^>]+>");
                str = reg.Replace(str, "");
                MessageBox.Show(str);
      

  7.   

    没用呀。
    网上说要用到什么平衡组之类的,但例子是只针对Div的:
    平衡组的一个最常见的应用就是匹配HTML,下面这个例子可以匹配嵌套的<div>标签:<div[^>]*>[^<>]*(((?'Open'<div[^>]*>)[^<>]*)+((?'-Open'</div>)[^<>]*)+)*(?(Open)(?!))</div>.
    能不能帮我改成用于<o:xxx的?注:表达式最后的.不知道是不是半角句号。
      

  8.   


    <p class=MsoNormal><span lang=EN-US><img width=553 height=415 src="f:\74673d12-ca8a-4fc8-9324-f6d2b0b7268c.jpg" v:shapes="_x0000_i1025"></span></p>  <p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>  <p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>  <p class=MsoNormal><span lang=EN-US>32</span><span lang=EN-US style='font-size: 18.0pt'>41</span><span lang=EN-US>231<span style='background:yellow;mso-highlight: yellow'>42314</span></span></p>  
    结果:<p class=MsoNormal><span lang=EN-US><img width=553 height=415 src="f:\74673d12-ca8a-4fc8-9324-f6d2b0b7268c.jpg" v:shapes="_x0000_i1025"></span></p>  <p class=MsoNormal><span lang=EN-US></span></p>  <p class=MsoNormal><span lang=EN-US></span></p>  <p class=MsoNormal><span lang=EN-US>32</span><span lang=EN-US style='font-size: 18.0pt'>41</span><span lang=EN-US>231<span style='background:yellow;mso-highlight: yellow'>42314</span></span></p>  
    就是这样,目前不考虑深度嵌套的问题。
      

  9.   

    string str = @"<p class=MsoNormal><span lang=EN-US><img width=553 height=415 src=""f:\74673d12-ca8a-4fc8-9324-f6d2b0b7268c.jpg"" v:shapes=""_x0000_i1025""></span></p>  <p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>  <p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>  <p class=MsoNormal><span lang=EN-US>32</span><span lang=EN-US style='font-size: 18.0pt'>41</span><span lang=EN-US>231<span style='background:yellow;mso-highlight: yellow'>42314</span></span></p>";
                Regex reg = new Regex(@"(?is)<o:[^>]+>.*?</o:[^>]+>");
                str = reg.Replace(str, "");
                MessageBox.Show(str);
    这样可以啊