我有一个看起来像的字符串"<name><address> and <Phone_1>"
。我必须得到这样的结果
1) <name>
2) <address>
3) <Phone_1>
我尝试使用正则表达式“ <(。*)>”,但它仅返回一个结果。
您想要的正则表达式是
<([^<>]+?)><([^<>]+?)> and <([^<>]+?)>
然后,这将吐出您想要的3个捕获组中的内容。完整的代码将如下所示:
Matcher m = Pattern.compile("<([^<>]+?)><([^<>]+?)> and <([^<>]+?)>").matcher(string);
if (m.find()) {
String name = m.group(1);
String address = m.group(2);
String phone = m.group(3);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句