Regular expressions in "Replace with"?

Is Pallada or 4.0 supposed to support regular expressions in the
"Replace with" part of a "Replace in Path" that you would want for
things like capture groups. The Help documentation isn't clear on this
point so I don't know whether to file a bug or feature request.

Thanks,
Jon

9 comments
Comment actions Permalink

Yes, IDEA supports capture groups when searching/replacing for regular expressions. I've used this quite a couple of times.

0
Comment actions Permalink

Marcus,

Super. I was getting caught with the $1 versus \1 for capture groups.

Thanks,
Jon

Marcus Brito wrote:

Yes, IDEA supports capture groups when searching/replacing for regular expressions. I've used this quite a couple of times.

0
Comment actions Permalink

Hello, Marcus!
You wrote on Fri, 7 May 2004 00:47:19 +0400 (MSD):

MB> Yes, IDEA supports capture groups when searching/replacing for
MB> regular expressions. I've used this quite a couple of times.

BTW, maybe i seems to me as bkoken Replace in Path functionality, but i saw
that i must perform two times run search for full replacing. First replace
run unfortunaly don't replace all occupances...

Alexey Efimov - Java Developer
Tops BI
http://www.topsbi.com


0
Comment actions Permalink

I keep making the same mistake.

It would be nice if the syntax was clearly identified somewhere; like in a
tooltip, or at least in the help documentation.

Tim

"Jon Steelman" <jon@cc.gatech.edu> wrote in message
news:c7edch$22n$1@is.intellij.net...

Marcus,

>

Super. I was getting caught with the $1 versus \1 for capture groups.

>

Thanks,
Jon

>

Marcus Brito wrote:

Yes, IDEA supports capture groups when searching/replacing for regular

expressions. I've used this quite a couple of times.


0
Comment actions Permalink

Agreed! How about filing a feature request? Part of the issue is that
the javadoc documentation itself only mentions the $# on one of the
replace methods and not in the class javadocs that mention everything
else. So, Java documentation is weak on that issue which propagates
everywhere that documents regex. Even the regex plugin doesn't mention $#.

Jon

Tim Haley wrote:

I keep making the same mistake.

It would be nice if the syntax was clearly identified somewhere; like in a
tooltip, or at least in the help documentation.

Tim

"Jon Steelman" <jon@cc.gatech.edu> wrote in message
news:c7edch$22n$1@is.intellij.net...

>>Marcus,
>>
>>Super. I was getting caught with the $1 versus \1 for capture groups.
>>
>>Thanks,
>>Jon
>>
>>Marcus Brito wrote:
>>
>>>Yes, IDEA supports capture groups when searching/replacing for regular


expressions. I've used this quite a couple of times.

0
Comment actions Permalink

From j2sdk1.4.2_04 javadoc for java.util.regex.Pattern:

"In Perl, \1 through \9 are always interpreted as back references; a
backslash-escaped number greater than 9 is treated as a back reference if at
least that many subexpressions exist, otherwise it is interpreted, if
possible, as an octal escape. In this class octal escapes must always begin
with a zero. In this class, \1 through \9 are always interpreted as back
references, and a larger number is accepted as a back reference if at least
that many subexpressions exist at that point in the regular expression,
otherwise the parser will drop digits until the number is smaller or equal
to the existing number of groups or it is one digit. "

Based on that, I would expect \1 to reference the first group captured.

The following is buried in only two of the method descriptions for
java.util.regex.Matcher:
"Dollar signs may be treated as references to captured subsequences..."

So, unless you are an expert in using the java.util.regex package, you would
probably not know the syntax.

For all of us who don't use the java.util.regex package on a regular basis,
the IDEA documentation should make it clear.



"Evgueny Vigdorchik" <ven@intellij.com> wrote in message
news:c7g3q4$htr$1@is.intellij.net...
>

"Tim Haley" <ymaraner@yahoo.com> wrote in message
news:c7ftou$80o$1@is.intellij.net...

I keep making the same mistake.

>

It would be nice if the syntax was clearly identified somewhere; like in

a

tooltip, or at least in the help documentation.

>

The syntax is precisely java.util.regex. So it is documented in
corresponding java docs.

>
>


0
Comment actions Permalink

True; but that is not obvious to the casual observer.

Hence the request for clarification in IDEA.

"Gordon Tyler" <gordon.tyler@quest.com> wrote in message
news:c7gf0g$ofi$1@is.intellij.net...

Tim Haley wrote:

>

Based on that, I would expect \1 to reference the first group captured.

>

The following is buried in only two of the method descriptions for
java.util.regex.Matcher:
"Dollar signs may be treated as references to captured subsequences..."

>

If I understand correctly, back references are used within the Find
expression to refer to groups captured earlier in the expression. For
example, the expression "(foo)bar\1" would match "foobarfoo".

>

The Replace expression can contain $ references to the captured groups.
For example, using the above find expression, the replace expression
"acme$1" would evaluate to "acmefoo".

>

Ciao,
Gordon

>

--
Gordon Tyler (Software Developer)
Quest Software <http://java.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: 416-643-4846 | Fax: 416-594-1919



0

Please sign in to leave a comment.