Groovy web console

subscribe to the feed Subscribe
to this
site
regex1 (via #groovywebconsole)
tweet this snippet Tweet
this
script

regex1

Published 5 months ago by d
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def str = "Accounts payable : Finance (2017)"

def newstr = str.toLowerCase().trim().replaceAll("\\s+|[^0-9a-zA-Z{}_]+", "_")
def newstr2 = str.toLowerCase().trim().replaceAll("\\s+", "_").replaceAll("[^0-9a-zA-Z{}_]+", "")

println newstr
println newstr.replaceAll("\\_+", "_")
println newstr2
println newstr2.replaceAll("\\_+", "_")