我有一个字符串:“/ontology/concepts.owl#Altitude>, /ontology/Concepts.owl#Height>”
我想通过在字符串中查找两个特殊字符(“#”和“>”)来找到“Altitude” and “Height”
字符的顺序很重要,例如“>, /ontology/Concepts.owl”
不应该是String.split(“#|>”)的结果,该结果返回包含““>, /ontology/Concepts.owl”.
的结果。这个 ?
提前致谢,
苏德
最佳答案
尝试这个
String s = "/ontology/concepts.owl#Altitude>, /ontology/Concepts.owl#Height>";
Matcher m = Pattern.compile("#(.+?)>").matcher(s);
while(m.find()) {
System.out.println(m.group(1));
}
输出
Altitude
Height