Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » [3.0 M5] Regular expression replacement expressions...
[3.0 M5] Regular expression replacement expressions... [message #167129] Mon, 08 December 2003 07:35 Go to next message
Eclipse UserFriend
Originally posted by: marcus.edwards.digitalsteps.com

Hi,

I'm trying to determine whether the following is a bug or a
misunderstanding/misconfiguration on my part. The problem seems to be that
when using regular expressions, the replace field with group expression is
no longer working.

Test case:
- open java perspective, open java source file
- Ctrl+F to bring up the search and replace dialog
- enter a search expression including a group, e.g. "Long ([^;]*);" -- find
all occurances of a Long field declarations.
- enter a replacement expression referencing the group, e.g. "Double \1;" --
change field type to Double.
- ensure 'Regular expressions' is checked on

Test data:
public class Test
{
private Long foo = new Long(123);
}

Results:
public class Test
{
private Double 1; // ?!? the regex matching group is being interpreted
as a literal
}

The regex help in the dialog indicates that I've got the right syntax so
something else must be wrong. I've tried various combinations including \\1.
/1. //1. \0 etc. all of which produce the wrong result.

Any ideas?

Thanks,
Marcus
Re: [3.0 M5] Regular expression replacement expressions... [message #167335 is a reply to message #167129] Mon, 08 December 2003 11:03 Go to previous messageGo to next message
Eclipse UserFriend
Marcus Edwards wrote:
> Hi,
>
> I'm trying to determine whether the following is a bug or a
> misunderstanding/misconfiguration on my part. The problem seems to be that
> when using regular expressions, the replace field with group expression is
> no longer working.
>
> Test case:
> - open java perspective, open java source file
> - Ctrl+F to bring up the search and replace dialog
> - enter a search expression including a group, e.g. "Long ([^;]*);" -- find
> all occurances of a Long field declarations.
> - enter a replacement expression referencing the group, e.g. "Double \1;" --
> change field type to Double.
> - ensure 'Regular expressions' is checked on
>
> Test data:
> public class Test
> {
> private Long foo = new Long(123);
> }
>
> Results:
> public class Test
> {
> private Double 1; // ?!? the regex matching group is being interpreted
> as a literal
> }
>
> The regex help in the dialog indicates that I've got the right syntax so
> something else must be wrong. I've tried various combinations including \\1.
> /1. //1. \0 etc. all of which produce the wrong result.

Java regex use $1 ... $n to refer to matched expressions, don't ask me why.

-tom
Re: [3.0 M5] Regular expression replacement expressions... [message #167370 is a reply to message #167335] Mon, 08 December 2003 12:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marcus.edwards.digitalsteps.com

"Tom Eicher" <eclipse@tom.eicher.name> wrote in message
news:br277g$9sb$1@eclipse.org...
> Java regex use $1 ... $n to refer to matched expressions, don't ask me
why.

<sarcasm>Fantastic</sarcasm>

I don't think this is a java regex problem though as java regex doesn't
provide for replacement expressions only search/matching expressions. This
must be the syntax that the Eclipse implementation has chosen to use. A
minor quick, but even so, there is a bug in the content assist help text.

Thanks for the assist.
Re: [3.0 M5] Regular expression replacement expressions... [message #167393 is a reply to message #167335] Mon, 08 December 2003 12:52 Go to previous messageGo to next message
Eclipse UserFriend
>
> Java regex use $1 ... $n to refer to matched expressions, don't ask me why.
>
> -tom
>
Because of perl I guess. (In perl they suggest to use $n instead of \n now).

Genady
Re: [3.0 M5] Regular expression replacement expressions... [message #167911 is a reply to message #167370] Tue, 09 December 2003 05:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: thomas_maeder.ch.ibm.com

??? java.util.regex.Matcher.replace(String replacement) ???

Marcus Edwards wrote:
> "Tom Eicher" <eclipse@tom.eicher.name> wrote in message
> news:br277g$9sb$1@eclipse.org...
>
>>Java regex use $1 ... $n to refer to matched expressions, don't ask me
>
> why.
>
> <sarcasm>Fantastic</sarcasm>
>
> I don't think this is a java regex problem though as java regex doesn't
> provide for replacement expressions only search/matching expressions. This
> must be the syntax that the Eclipse implementation has chosen to use. A
> minor quick, but even so, there is a bug in the content assist help text.
>
> Thanks for the assist.
>
>
Re: [3.0 M5] Regular expression replacement expressions... [message #168594 is a reply to message #167370] Wed, 10 December 2003 04:24 Go to previous message
Eclipse UserFriend
Originally posted by: marcus.edwards.digitalsteps.com

I stand corrected. The java.util.regex package does indeed support
replacement expressions and
uses the $n notation for replacement group matching as well.
Previous Topic:How to debug eclipse in eclipse?
Next Topic:Religion: netBeans vs. Eclipse
Goto Forum:
  


Current Time: Thu Nov 06 01:03:14 EST 2025

Powered by FUDForum. Page generated in 0.24490 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top