【发布时间】:2010-01-31 02:09:21
【问题描述】:
我看不出 Matcher 会在模式上返回匹配项的原因,但 split 会在相同的正则表达式模式上返回零长度数组。它应该返回一些东西——在这个例子中,我正在寻找包含“param/value”的 2 个单独字符串的返回。
public class MyClass {
protected Pattern regEx = "(([a-z])+/{1}([a-z0-9])+/?)*";
public void someMethod() {
String qs = "param/value/param/value";
Matcher matcherParamsRegEx = this.regEx.matcher(qs);
if (matcherParamsRegEx.matches()) { // This finds a match.
String[] parameterValues = qs.split(this.regEx.pattern()); // No matches... zero length array.
}
}
}
【问题讨论】: