Colin
Colin

Reputation: 670

Eclipse change case in regex find and replace

In Eclipse, I would like to be able to do a regex search and replace for some text and slightly modify it, changing the case of one of the letters. For example: find myVariable.getProperty() and change it to myVariable.property.

I can easily use myVariable.get(\w+)\(\) and replace it with myVariable.$1, but that results in myVariable.Property with the capital 'P'.

I believe this is possible with some regex engines, but I cannot find a way to do it within Eclipse.

Upvotes: 4

Views: 2941

Answers (1)

Andrew
Andrew

Reputation: 315

I don't think eclipse supports that type of functionality. You would have to get "creative" and do things like:

Search: myVariable\.getP(\w+)\(\)

Replace: myVariable\.p(\1)

But according to regular-expresions.info (http://www.regular-expressions.info/replacecase.html), if you're open to editing your JSP file with a different text editor, there are programs that use other flavors of RegEx which can make your change.

Using your example, EditPad Lite for instance would allow your search:

Search: (myVariable\.)get(\w+)\(\)

And replace it with:

Replace: \1\L2

This would result in:

myVariable.getProperty()

to:

myVariable.property

In this case \L2 changes the contents of the second back reference to a lowercase version. \U2 would change it to uppercase. \I0 would capitalize the initial letter of each separated word in the string and \F0 would capitalize just the first letter of your string.

I've done similar things for small but repetitive changes where eclipse is not exactly equipped for the job. And then go back to eclipse when the change has gone through.

Upvotes: 2

Related Questions