Back reference in regexp replacement

May I know why the Java Regex syntax for back-reference ($0 and $&) is not supported in IDEA when using the replace dialog?

5 comments
Comment actions Permalink

It is. Are you sure you've got the Replace dialog in Regular Expression mode?

And, of course, while $0 is always available, $1 and greater only work when there's a capturing group that  matched in the RE.


Randall Schulz

0
Comment actions Permalink

Ok...I'm now posting a TC here:

Env : IDEA 8.1.3, WinXP

  1. Insert text "bughere" into document;
  2. Open replace dialog with RE mode turned on;
  3. Input 'bug(?=here)' inside 'Text to find' box;
  4. Input '$0' in 'Replace with' box;
  5. Click 'Find', on the first match click 'Replace'
  • Expected: the text remain unchanged;
  • Actual: text been replaced as '$0here'.
0
Comment actions Permalink

It looks like the look-ahead sub-expr breaks something. If you don't use that, it works. E.g., if you match (bug)(here) and replace with $0 or with $1$2, it works.

Since you found it, you have the honor of submitting the YouTrack report, after checking to make sure it's not already reported, of course.


Randall Schulz

0
Comment actions Permalink

Bug reported here, thanks for the help.

0
Comment actions Permalink

HI,

I added a note to the bug report mentioning that it occurs for me in 8.1.3, too. Then I noticed that here in the forum you said you were using 8.1.3, but in the bug report it is labeled "Affected versions: Maia EAP 10762"


Randall Schulz

0

Please sign in to leave a comment.