Groovy web console

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

Matcher

Published 2 weeks ago by Hardik Modha with tags Matcher Regex
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts

import java.util.regex.Matcher
import java.util.regex.Pattern

String selector = 'node.val'
Matcher matcher = Pattern.compile('\\[([^]]+)\\]').matcher(selector)
println Matcher.isInstance(matcher)
if (matcher.find()) {
    println matcher.group(1)
}