Groovy web console

subscribe to the feed Subscribe
to this
site
expand a string by number times by adding previous character (via #groovywebconsole)
tweet this snippet Tweet
this
script

expand a string by number times by adding previous character

Published 6 months ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def input = "AA3BBCD100"

def what_multyplays = input.findAll("[A-Za-z]{1}[0-9]+")
def output = input

for (what_multyplay in what_multyplays){
    def replase = what_multyplay[0] * what_multyplay.substring(1).toInteger()
    output = output.replace(what_multyplay, replase)
    
}

println(output)