Friday, October 07, 2011

Some cool Eclipse regexes

I have this line of text :

public Integer getAccountId() { return account_id.getInteger(); }

And I need to turn it into :

public void setAccountId(Integer value) { return account_id.getInteger(); }

One regex can do that for me as follows :

Find:
(public\ )([A-Za-z]+)\ g([A-Za-z]+\()(\)\t+\{\ )(return\ )([A-Za-z_]+\.)(g)([A-Za-z]+\()

Replace:
$1void s$3$2 value$4$6s$8value

Thats it. Yay. Nice and simple!