While searching something on net I found an interesting method of groovy collectReplacements. This method iterate through the string character by character and replace the matching character with the given string. This method take closure as an argument.

Here you can also have multiple conditions like

Also we can achieve the same result via switch cases.

Note:- Closure should return null to indicate no transformation is required for the given character.

Note:- I have tested it on grails 2.3.0(groovy 2.1.6).