0

I need to replace all occurrences of abc with xyz, but only if they occur in Javadoc comments.

I am using Eclipse.

I believe requiring simply that the line starts either with \s*\* or \s/\* should be sufficient for my purposes (no need to match for "occurs between /** and */", but that would work fine too).

I tried using: (\s\*|\s/\*)(.*)abc and replacing with $1$2xyz but the problem is that the regex is greedy so it gives me only the longest line that matches my string (i.e., I can only replace the last abc on any given line). Is there any way to ask it for all the possibilities, or is that outside of the scope of (non-recursive) regular expressions?

If it is outside the scope, would a recursive expression work? (Which Eclipse does not support in any case).

Mark Chimes
  • 295
  • 1
  • 11
  • Did you go through a fine answer already written [here](http://stackoverflow.com/questions/689007/search-javadoc-in-eclipse) ? – SomeDude Apr 06 '17 at 16:14
  • I don't think you understood my needs. That answer finds the *entire comment*. I need a way to be able to essentially be able press 'find' twice and find each one in turn so that I can just press 'replace all' once and get all of them. – Mark Chimes Apr 07 '17 at 07:51

1 Answers1

0

To my knowledge this is not possible. A regex traverses each character of the input text once and it can't go back.

You can either match on the first abc or the last abc of a JavaDoc line, because by the time it has matched on either of them, the characters defining that line as a JavaDoc comment can't be matched again.

Luciano van der Veekens
  • 6,307
  • 4
  • 26
  • 30
  • Ah ok. I worried it would be like that. I'll just build a Python script or something. Thanks! – Mark Chimes Apr 07 '17 at 09:11
  • Okay. Does saying "your issue does not have a solution" count as "solved"? By the way, in the end I just checked and saw that "abc" wasn't being used outside of comments in any case, so I just find/replaced them. – Mark Chimes Apr 18 '17 at 13:34
  • @MarkChimes Well, you were asking if there is a way to do so, indicating a "Yes" or "No" answer. – Luciano van der Veekens Apr 18 '17 at 13:46