http://NDIvMS8xNi9sZXR2LXV0cy84NzAzMjgzLWF2Yy0yNTQyMzctYWFjLTMxNTg2LTI3MDQyNDAtMTAwODM1ODY2LTQyYmNiZjhhMjY2OTAzMGNjNjAwNDJkODE3YjRlY2ZmLTEzODUzOTM0NTE0MzMuZmx2?b=
http://NDIvMS8xNi9sZXR2LXV0cy84NzAzMjkwLWF2Yy0xNjExMzU4LWFhYy0xMjQzNjktMjcwNDI0MC02MDM1NzQ0NzgtNGNjNmQ5NzQ0NzY4Y2EyOWM5ZmVjN2YzYWY2Yjc4MDEtMTM4NTM5OTQzNjM2My5mbHY=?b=
http://NDIvMS8xNi9sZXR2LXV0cy84NzAzMjg4LWF2Yy05MzczNTUtYWFjLTEyNDM2OS0yNzA0MjQwLTM3MDI3NjYwNS1mMGY0NWVlMDZhMGE1MjliNGJjMzM2ZTkzNTBjNWQwYS0xMzg1Mzk4OTcwMjk2LmZsdg==?b=
final static Pattern PATTERN_JSON_OF_RAND = Pattern.compile("http://([0-9a-zA-Z]+?)?b=");
进行正则表达式的时候
Matcher m = PATTERN_JSON_OF_RAND.(html);
if (!m.find())
throw......//出现没有找到,
哪位大婶能帮我改改正则表达式,加下划线的地方为要匹配的地方。
------解决方案--------------------
因为地址是base64的所以不会出现"?"
Pattern PATTERN_JSON_OF_RAND = Pattern.compile("(?<=http://)\\w+?(?=\\?)");
Matcher m=PATTERN_JSON_OF_RAND.matcher(html);
while(m.find()){
System.out.println(m.group());
}
------解决方案--------------------
你的第二个问好转一下义http://([0-9a-zA-Z]+?)\\?b=
public static void main(String[] args) {
String html = "http://NDIvMS8xNi9sZXR2LXV0cy84NzAzMjgzLWF2Yy0yNTQyMzctYWFjLTMxNTg2LTI3MDQyNDAtMTAwODM1ODY2LTQyYmNiZjhhMjY2OTAzMGNjNjAwNDJkODE3YjRlY2ZmLTEzODUzOTM0NTE0MzMuZmx2?b=http://NDIvMS8xNi9sZXR2LXV0cy84NzAzMjkwLWF2Yy0xNjExMzU4LWFhYy0xMjQzNjktMjcwNDI0MC02MDM1NzQ0NzgtNGNjNmQ5NzQ0NzY4Y2EyOWM5ZmVjN2YzYWY2Yjc4MDEtMTM4NTM5OTQzNjM2My5mbHY=?b=http://NDIvMS8xNi9sZXR2LXV0cy84NzAzMjg4LWF2Yy05MzczNTUtYWFjLTEyNDM2OS0yNzA0MjQwLTM3MDI3NjYwNS1mMGY0NWVlMDZhMGE1MjliNGJjMzM2ZTkzNTBjNWQwYS0xMzg1Mzk4OTcwMjk2LmZsdg==?b=";
final Pattern PATTERN_JSON_OF_RAND = Pattern
.compile("http://([0-9a-zA-Z]+?)\\?b=");
Matcher m = PATTERN_JSON_OF_RAND.matcher(html);
while (m.find()) {
System.out.println(m.group());
}
}
------解决方案--------------------
依据BASE64的规则完全匹配,再找出楼主要求的一划线的值:
public class Test {
public static void main(String[] args) {
//base64: a-z A-Z 0-9 / + =
String http =
"http://jZmLTEzODUzOTM0NTE0MzMuZmx+2?b="+
"http://NmQ5NzQ0NzY4Y2EyOWM5ZmVjN2/Y=?b="+
"http://NDM2OS0yNzA0MjQwLTM3MDI3N/+jY==?b=";
String reg = "http://([A-Za-z0-9\\+/=]+)\\?b=";
java.util.regex.Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(http);
while(m.find()){
System.out.println(m.group(1));
/**
* http://jZmLTEzODUzOTM0NTE0MzMuZmx+2
http://NmQ5NzQ0NzY4Y2EyOWM5ZmVjN2/Y=
http://NDM2OS0yNzA0MjQwLTM3MDI3N/+jY==
*/
}
}
}