I am attempting to do some find and replace on a java source file.
Currently my classes have invalid names (imported from a tool that did poor auto naming) of the form:
public class [0-9]{2}[A-Za-z]+
I would like to insert underscores around the digits, resulting in a valid class name of the form
public class [_][0-9]{2}[_][A-Za-z]+
However using Eclipses find and replace tool, with the regex box check on both the find and replace strings does not format the output as I’d like.
It takes
02ListOfValidAppIDs
and makes it
[-][0-9]{2}[_][A-Za-z]+
instead of
_02_ListOfValidAppIDs
How can you make the regex keep the arbitrary number and text and just plug them in for the replace string?
(Edit: As a note, with the preview feature I can see that eclipse is correctly finding all of the names I wish to replace, and nothing else)
I’m not sure of the exact flavor of Regex that you’ll need, but something like this should get you started in the right direction.
Update your “Find” pattern to use capture groups:
And then reference those captures in the replacement:
NOTE: Some flavors of Regex will use
{}instead of()to represent a captured group, and some flavors will use$1,$2,$3, etc. as the reference instead of using\#.