For simplicity, I would go with:
def pin = "EUTQQGOPED"
def formatted = [pin[0..2], pin[3..5], pin[6..-1]].join('-')
For brevity, this can be a hack, but it is very short (and I think it is readable enough):
def formatted = "-$pin"[1..3, 0, 4..6, 0, 7..10]
source
share