Groovy web console

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

regex-search

Published 2 months ago by jaxzin
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def config = [
    jenkins: [enabled: 1],
    jobs: [
        "lightbake": [
            jenkins: [enabled: 2],
        ]
    ],
    branches: [
        "test-lightbake": [jenkins: [enabled: 3]],
        ".+-lightbake"  : [jenkins: [enabled: 4]]
    ]
]

def branch = "test-lightbake"
def path = "jenkins?.enabled"

def ex = ".+-lightbake"
def regex = /$ex/

println (("foo-lightbake" =~ regex)?.matches()) // true
println (("foo" =~ regex)?.matches()) // false

//println config.branches.find{"foo-lightbake" =~ /it.key/}

def evalex = """x?.branches?.find{"$branch" =~ /\${it.key}/}?.value?.${path} ?: x?.${path}"""
//println evalex
Eval.x(config, evalex)