String a = "<a href=/"
http://www.dd.com/1.mp3/">http://wds.mp3</a>";
String re = "< //s*a//s+href//s*=//s*/"|//s*/"//s*>|<(.[^>]*)>"; //取地址和中文
String regex = "< //s*a//s+href//s*=//s*/"|//s*/"//s*>"; //取地址
String reg = "<(.[^>]*)>"; //取中文
Pattern p = Pattern.compile(re);
Matcher math = p.matcher(a);
StringBuffer bs = new StringBuffer();
boolean b = math.find();
while (b) {
math.appendReplacement(bs, "");
b = math.find();
}
math.appendTail(bs);
System.out.println(bs);
String re = "< //s*a//s+href//s*=//s*/"|//s*/"//s*>|<(.[^>]*)>"; //取地址和中文
String regex = "< //s*a//s+href//s*=//s*/"|//s*/"//s*>"; //取地址
String reg = "<(.[^>]*)>"; //取中文
Pattern p = Pattern.compile(re);
Matcher math = p.matcher(a);
StringBuffer bs = new StringBuffer();
boolean b = math.find();
while (b) {
math.appendReplacement(bs, "");
b = math.find();
}
math.appendTail(bs);
System.out.println(bs);
博客展示了Java代码中使用正则表达式处理字符串的过程。定义了不同的正则表达式用于提取地址和中文,通过Pattern和Matcher类进行匹配操作,最后将匹配结果替换并输出处理后的字符串,体现了正则表达式在字符串处理中的应用。
1884

被折叠的 条评论
为什么被折叠?



