String url="http://www.baidu.com/s?wd=%CC%EC%BB%A8%B0%E5";
Pattern wd= Pattern.compile("[&|\\?]wd=(.+)[&|$]");
java.util.regex.Matcher m = P_WD.matcher(url);
if (m.find())
{
String keywords = m.group(1);
System.out.println(keywords+":"+java.net.URLDecoder.decode(keywords, "GBK"));
}
如果 url="http://www.baidu.com/s?wd=%CC%EC%BB%A8%B0%E5&ie=gb2312" 这是可以取出关键字的. 为什么 url="http://www.baidu.com/s?wd=%CC%EC%BB%A8%B0%E5"; 这样就不行???哪位大侠帮看看??
Pattern wd= Pattern.compile("[&|\\?]wd=(.+)[&|$]");
java.util.regex.Matcher m = P_WD.matcher(url);
if (m.find())
{
String keywords = m.group(1);
System.out.println(keywords+":"+java.net.URLDecoder.decode(keywords, "GBK"));
}
如果 url="http://www.baidu.com/s?wd=%CC%EC%BB%A8%B0%E5&ie=gb2312" 这是可以取出关键字的. 为什么 url="http://www.baidu.com/s?wd=%CC%EC%BB%A8%B0%E5"; 这样就不行???哪位大侠帮看看??
--------
我也是这样理解的呀例: http://www.baidu.com/s?wd=%CC%EC%BB%A8%B0%E5%CC%EC%BB%A8%B0%E5 之后没有东西了吧, 这应该叫"一行的结尾"吧为什么取不出来
%CC%EC%BB%A8%B0%E5呀?????????
String f = "[&|\\?]wd=(.+)";
if (args.indexOf("&") != -1)
f = "[&|\\?]wd=(.+)[&]"; Pattern p = Pattern.compile(f);
Matcher m = p.matcher(args);
if (m.find())
return m.group(1).toString();
else
return "";
}
xx$跟xx[$]不一样,楼主试试就知道了