用正则表达式取字符串的问题 有必要用到正则表达式吗??直接检测<p>和</p>不就行了?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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());}} 改成下面这个更好些!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());}} hashcode问题比较 教授布置的一个JAVA小项目.请老鸟给点建议. ))急急急!!wap页面上wml标签空格显示(( 谁能看看这两个递归函数有什么区别 求助!我是初学者,问几个基础的题目? 这些题都是正确的吗?? \u4f60\u597d怎样转为中文? 想不明白的问题,请指点 帮我解释一下这个异常 ----------------- 50分向赠 什么时候父类能强制转换成子类?? 请教各位,我用frontpage中插入applet却显不出来为什么?? 重新回到java阵营,大散分(500)(请斑竹留情)元旦后就揭帖,祝各位新年快乐!大家的努力会让冬天赶快过去,呵呵!
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());
}
}
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());
}
}