props.put(prefix + s, sub[i]);
matches++;
}
}
} else if (match != null) {
Regexp r;
try {
r = new Regexp(match, hr.isTrue("nocase"));
String replace = hr.get("replace");
boolean all = hr.isTrue("all");
if (replace != null) {
String result;
if (all) {
result = r.subAll(value, replace);
} else {
result = r.sub(value, replace);
}
props.put(prefix + "replace",
result==null ? nullStr :result);
} else {
int subMatches = Math.min(MAX_MATCHES, r.subspecs());
String[] sub = new String[subMatches];
if (all) { // all matches
Regsub rs = new Regsub(r, value);
StringBuffer counter = new StringBuffer();
while(rs.nextMatch()) {
matches++;
props.put(prefix + matches, rs.matched());
for (int i = 1; i < subMatches; i++) {
String s = mapTable.length >= i ? mapTable[i-1] : "" + i;
props.put(prefix + matches + "." + s,
(rs.submatch(i)==null ? nullStr : rs.submatch(i)));
}
counter.append(matches + " ");
}
if (matches>0) {
props.put(prefix + "submatches", "" + subMatches);
props.put(prefix + "matchlist", counter.toString());
}
} else if (r.match(value, sub)) { // first match
for (int i = 0; i < sub.length; i++) {
if (sub[i] == null) {
sub[i] = "";
}
props.put(prefix + i, sub[i]);