有一段文字如下
测试开头<table><tr><td>测试文字</td></tr></table><br/><p>测试p</p>测试结尾
这段文字中我需要将不是br和p的标签的括号替换成相应的转义字符,如<table>替换成&#60;table&#62;  但是<p>不做替换
请问这样的正则表达式该如何写?

解决方案 »

  1.   

    class Test {
      public static void main(String[] args) {
        String str = "测试开头<table><tr><td>测试文字</td></tr></table><br/><p>测试p</p>测试结尾";
        System.out.println(str);
        System.out.println(str.replaceAll("<(?!br)(?!p)[^>]+?>", ""));
      }
    }
      

  2.   

    System.out.println(str.replaceAll("<(?!/?br)(?!/?p)(.*?)>", "&#60;$1&#62;"));
      

  3.   

    分数不够,借用一下:
    editplus 正则表达式怎样替换这样的表达式:
    /*     */
    /*  47 */
    /*  56 */
    谢谢 !
      

  4.   


    notepad++:(/\*)(\*/)
    \147\2
      

  5.   

    给你一个完整版的吧,呵呵
    class Test {
      public static void main(String[] args) {
        String str = "测试开头<table><tr><td>测试文字</td></tr></table><br/><p>测试p</p>测试结尾";
        System.out.println(str);
        System.out.println(str.replaceAll("<(?!br)(?!p)([^>]+?)>", "&#60;$1&#62;"));
      }
    }
      

  6.   

    <html>
    <title>test embed video</title>
    <embed src="http://player.56.com/v_NTEyMTc3MjE.swf"  type="application/x-shockwave-flash" width="480" height="395"></embed>
    </html>
    test