Community
Participate
Working Groups
With regular expressions enabled in the find/replace dialog, you can currently echo matched groups using the syntax $groupNumber in the replace string. So for example, with the find string "(\w)" you can echo the matched group with "$1" in the replace string. However, the group echo syntax used for ex, sed, ed, vim, and other GNU utilites is \groupNumber. I would like to see \groupNumber as an accepted syntax for echoing groups. It appears that java.util.regex is used for the underlying replacement, and adding this feature may be as simple as applying the following substitution to the replace string before it is used: replaceString.replaceAll("\\\\(\\d)+", "\\$$1") This was opened as <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=51136">bug 51136</a> originally.
We should find out whether this is a general regex problem or only a problem in some VMs. As a workaround we should offer \group syntax.
Just changing "\0" to "$0" in replace strings would make a certain set of replacements impossible. The fix for bug 80667 contains a workaround for this problem: /* * Feature in java.util.regex.Matcher#replaceFirst(String): * $00, $000, etc. are interpreted as $0 and * $01, $001, etc. are interpreted as $1, etc. . * If we support \0 as replacement pattern for capturing group 0, * it would not be possible any more to write a replacement pattern * that appends 0 to a capturing group (like $0\0). * The fix is to consider \00 and $00 as $0\0, and * \01 and $01 as $0\1, etc. */
Thanks Markus. Committed to HEAD. Available in builds > N20070715-0010.