日期:2014-05-20 浏览次数:20799 次
import java.util.regex.*;
public class Test {
public static void main(String[] args) {
String ptn = ".*href=(.*\")";
Pattern p = Pattern.compile(ptn, Pattern.DOTALL);
String s = "asdfadfaadf-href=\"1alkjdflkajdfjalkdfj1\"adfadfhref=\'1alkjdflkajdfjalkdfj1\'ad"; // \" 转义 ,表示"
Matcher m = p.matcher(s);
if (m.find()) {
System.out.println("href="+m.group(1));
} else {
System.out.println("not match");
}
}
}
href="1alkjdflkajdfjalkdfj1"
static String ptn = "href=[\"
------解决方案--------------------
\'](.+?)[\"
------解决方案--------------------
\']";
static Pattern p = Pattern.compile(ptn);
public static void find(String str){
Matcher m = p.matcher(str);
while (m.find()) {
System.out.println(m.group(1));
}
}