| Summary: | [find/replace] Regular expression replace does not handle groups | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Ken Collins <ken> |
| Component: | Text | Assignee: | Platform-Text-Inbox <platform-text-inbox> |
| Status: | RESOLVED WORKSFORME | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | ||
| Version: | 3.0 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Whiteboard: | |||
|
Description
Ken Collins
It supports groups. You can use \aGroupNumber in the find string and $aGroupNumber in the replace string. It should support \aGroupNumber in the replace string as well. I have to check why the regex package which we are using isn't doing so. According to its doc (see F1) it should. I got the $aGroupNumber syntax you described to work. Where did the $aGroupNumber syntax come from? I'm only familiar with \aGroupNumber which is standard for ex, sed, ed, and vim. I couldn't get F1 to bring up help, and before I submitted this bug I did a Help Contents search for regex and came up with nothing. I found docs on the "Finding and Replacing" task, but it didn't mention regexes or group matching. Are the docs not in 30m6, or are they not indexed? Should I submit a new feature request to support the \aGroupNumber syntax or just change the summary and status of this one? >I got the $aGroupNumber syntax you described to work. Where did the >$aGroupNumber syntax come from? From java.util.regex. package. >I couldn't get F1 to bring up help, When in the Find field pressing F1 opens help. Does F1 work in other dialogs? If not, first check your settings (Window > Preferences > Help) and if this does not help file a bug against Platform Help. >>I got the $aGroupNumber syntax you described to work. Where did the >>$aGroupNumber syntax come from? >From java.util.regex. package. Is this documented in java.util.regex.Pattern? I didn't see anything that mentioned '$' except for end of line matching. The groups are numbered, but I don't know where '$' is associated with the group for substitutions. I'll check 3.0m7 and see if \aGroupNumber in the replace strings is working again. >When in the Find field pressing F1 opens help. Does F1 work in other dialogs? If >not, first check your settings (Window > Preferences > Help) and if this does >not help file a bug against Platform Help. F1 isn't doing anything in either the find or replace fields. It's not working elsewhere, either. I'll check in 3.0m7 when it comes out. >I'll check 3.0m7 and see if \aGroupNumber in the replace strings is working >again.
It won't. We use the regex package upon which we do not have an influence. The
fact is that it works as I described. No idea why it is not documented along
with the regex package.
Note: F1 not working will not work with M7 if it doesn't work now.
> It won't. We use the regex package upon which we do not have an influence. The
> fact is that it works as I described. No idea why it is not documented along
> with the regex package.
So the replace is using something like matcher.replaceAll(), and this is why the
familiar "\aGroupNumber" syntax isn't working? Couldn't Eclipse's replace simply
be rewritten so that it substitutes \aGroupNumber for $aGroupNumber in the
replace string before applying it? Something like:
matcher.replaceAll(replaceString.replaceAll("\\\\(\\d)+", "\\$$1"));
If that's the case, can I reopen this as a feature request?
I think it would be better to use a widely adopted convention rather than one
unique to Java regex that's not documented.
Yes you can enter such a feature request. But first we have to verifiy what the plan for the regex package is i.e. maybe it gets fixed there. |