51,409
社区成员
发帖
与我相关
我的任务
分享
String str = "<ms id='001' to=\"test@127.0.0.1'test1@127.0.0.1\" from='test2@127.0.0.1'><body>你好</body><x>xyz</x></ms>";
Pattern p = Pattern.compile("to=(((?:')[^']*(?:'))|(?:\")[^\"]*(?:\"))");
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group());
}

public static void main(String[] args) {
String str = "<ms id='001' to=\"test@127.0.0.1'test1@127.0.0.1\" from='test2@127.0.0.1'><body>你好</body><x>xyz</x></ms>";
Pattern p = Pattern.compile("((?<=to=')([^']*)(?='))|((?<=to=\")([^\"]*)(?=\"))");
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group());
}
}
String str = "<ms id='001' to=\"test@127.0.0.1'test1@127.0.0.1\" from='test2@127.0.0.1'><body>你好</body><x>xyz</x></ms>";
Pattern p = Pattern.compile("to=(((?:')([^']*)(?:'))|((?:\")([^\"]*)(?:\")))");
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group());
}