我必须从url获取jsessionid代码而不是jsessionid字符串。有可能匹配并排除它吗?
https://esgf-data.dkrz.de/esgf-idp/idp/login.htm;jsessionid=436100313FAFBBB9B4DC8BA3C2EC267B
Result = 436100313FAFBBB9B4DC8BA3C2EC267B
评论添加的代码:
Pattern pattern = Pattern.compile("/jsessionid=([a-z0-9]+)/i");
Matcher matcher=pattern.matcher(connection.getURL().toExternalForm());
答案 0 :(得分:0)
/=([A-Z0-9]+)/
将在等号=
之后获取全部大写和数字,并将其移至反向引用#1
$subject = 'https://esgf-data.dkrz.de/esgf-idp/idp/login.htm;jsessionid=436100313FAFBBB9B4DC8BA3C2EC267B';
if (preg_match('/=([A-Z0-9]+)/', $subject, $regs)) {
$result = $regs[1];
} else {
$result = "";
}
答案 1 :(得分:0)
试试这个:
String data = "https://esgf-data.dkrz.de/esgf-idp/idp/login.htm;jsessionid=436100313FAFBBB9B4DC8BA3C2EC267B";
Pattern pattern = Pattern.compile("jsessionid=(\\w+)");
Matcher matcher = pattern.matcher(data);
while (matcher.find()) {
System.out.println("Result is : " + matcher.group(1));
}
答案 2 :(得分:0)