有必要用到正则表达式吗??
直接检测<p>和</p>不就行了??

解决方案 »

  1.   

    jdk1.4以上:
    import java.util.regex.*;public class test {
    public static void main(String args[]) {
        String str="<p>test1test2</p>";
        String str1="(<p>)(.+)(<\\/p>)";
        java.util.regex.Pattern p=Pattern.compile(str1);
        Matcher m=p.matcher(str);
        boolean f=m.find();
        StringBuffer sb=new StringBuffer();
        while(f) {
          m.appendReplacement(sb,"$2");
          f=m.find();
        }
        m.appendTail(sb);
        System.out.print(sb.toString());
    }
    }
      

  2.   

    改成下面这个更好些!
    public class test {
    public static void main(String args[]) {
        String str="<p>test1test2</p>";
        String str1="(<p>)(.*)(<\\/p>)";
        java.util.regex.Pattern p=Pattern.compile(str1);
        Matcher m=p.matcher(str);
        boolean f=m.find();
        StringBuffer sb=new StringBuffer();
        while(f) {
          m.appendReplacement(sb,"$2");
          f=m.find();
        }
        m.appendTail(sb);
        System.out.print(sb.toString());
    }
    }