- continue; // don't bother making the URL replacement text.
- }
- // do we take the cartesian products of the substituents ?
- int ns = rg.numSubs();
- if (ns == 0)
- {
- thematches[pass].append(rg.stringMatched());// take whole regex
- }
- /*
- * else if (ns==1) { // take only subgroup match return new String[]
- * { rg.stringMatched(1), url_prefix+rg.stringMatched(1)+url_suffix
- * }; }
- */
- // deal with multiple submatch case - for moment we do the simplest
- // - concatenate the matched regions, instead of creating a complete
- // list for each alternate match over all sequences.
- // TODO: specify a 'replace pattern' - next refinement
- else
- {
- // debug
- /*
- * for (int s = 0; s <= rg.numSubs(); s++) {
- * System.err.println("Sub " + s + " : " + rg.matchedFrom(s) +
- * " : " + rg.matchedTo(s) + " : '" + rg.stringMatched(s) + "'");
- * }
- */
- // try to collate subgroup matches
- StringBuffer subs = new StringBuffer();
- // have to loop through submatches, collating them at top level
- // match
- int s = 0; // 1;
- while (s <= ns)
- {
- if (s + 1 <= ns && rg.matchedTo(s) > -1
- && rg.matchedTo(s + 1) > -1
- && rg.matchedTo(s + 1) < rg.matchedTo(s))
- {
- // s is top level submatch. search for submatches enclosed by
- // this one
- int r = s + 1;
- StringBuffer rmtch = new StringBuffer();
- while (r <= ns && rg.matchedTo(r) <= rg.matchedTo(s))
- {
- if (rg.matchedFrom(r) > -1)
- {
- rmtch.append(rg.stringMatched(r));
- }
- r++;
- }
- if (rmtch.length() > 0)
- {
- subs.append(rmtch); // simply concatenate
- }
- s = r;
- }
- else
- {
- if (rg.matchedFrom(s) > -1)
- {
- subs.append(rg.stringMatched(s)); // concatenate
- }
- s++;
- }
- }
- thematches[pass].append(subs);