【发布时间】:2018-09-16 17:57:19
【问题描述】:
我有这个字符串:https://regex101.com/r/7Er0Ch/6
我想把我所有的http://esupb.tabriz.ir:808x/srvSC.svc 放入数组列表中。所以为了我使用 matcher,比如吹:
String regx= "#\\d+#";
Pattern pattern = Pattern.compile(regx);
Matcher matcher = pattern.matcher(url);
String[] metadata = new String[4];
while (matcher.find()) {
metadata[0] = matcher.group(1);
metadata[1] = matcher.group(2);
metadata[2] = matcher.group(3);
metadata[3] = matcher.group(4);
}
但我得到了不合适的结果。我的错误是什么?
【问题讨论】:
-
Matcher#groupCount()返回什么? -
是
matcher.groupCount() =1@pskink -
也许:
#\d+#(.*)#\d+#? regex101.com/r/7Er0Ch/7 -
你有
while (matcher.find()) {,所以用它来查找所有匹配项