Java 如何获取介于<;之间的字符串&燃气轮机;在爪哇
我有一个URL链接Java 如何获取介于<;之间的字符串&燃气轮机;在爪哇,java,regex,Java,Regex,我有一个URL链接 Link=<http://mysample.link.com/first/12/sample?page=1234-asdf>;rel="next" Link=;rel=“下一步” 我想获取之间的所有内容,并将结果作为http://mysample.link.com/first/12/sample?page=1234-asdf 目前我正在使用String.substring()像 finalString=sample.subString(sample.index
Link=<http://mysample.link.com/first/12/sample?page=1234-asdf>;rel="next"
Link=;rel=“下一步”
我想获取之间的所有内容,并将结果作为http://mysample.link.com/first/12/sample?page=1234-asdf
目前我正在使用String.substring()像
finalString=sample.subString(sample.indexOf(“”)代码>
但我认为这不是最好的办法。有人能告诉我如何使用正则表达式获取结果字符串吗 这里有一个正则表达式:
<([^>]+)>
]+)>
示例:我会使用这个:(?以下内容适用于您
String s = "Link=<http://mysample.link.com/first/12/sample?page=1234-asdf>;rel=\"next\"";
Pattern p = Pattern.compile("<([^>]+)>");
Matcher m = p.matcher(s);
while (m.find()) {
System.out.println(m.group(1));
}
// "http://mysample.link.com/first/12/sample?page=1234-asdf"
String s=“Link=;rel=\“next\”;
模式p=Pattern.compile(“]+)>”;
匹配器m=匹配器p;
while(m.find()){
系统输出println(m.group(1));
}
// "http://mysample.link.com/first/12/sample?page=1234-asdf“
您必须获取结果匹配的组(1)。非常感谢。也谢谢你的网站链接