search and replace loop example (java.util.regex -> org.apache.regexp)
Kevin Rodgers <[email protected]> Thu, 9 Sep 2004 16:13:44 -0600
| Newsgroups | gmane.comp.jakarta.regexp.user |
|---|---|
| Message-ID | <[email protected]> |
The Matcher.appendReplacement method has a great example of how to
efficiently replace matched text in a loop:
Pattern p = Pattern.compile("cat");
Matcher m = p.matcher("one cat two cats in the yard");
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, "dog");
}
m.appendTail(sb);
System.out.println(sb.toString());
(see http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Matcher.html)
What's the corresponding code using the RE class? Should Regexp include
a corresponding example in its documentation?
(see http://jakarta.apache.org/regexp/apidocs/org/apache/regexp/RE.html)
Thanks,
--
Kevin Rodgers