Skip to content

Instantly share code, notes, and snippets.

@shuji
Created April 8, 2012 01:08
Show Gist options
  • Save shuji/2333358 to your computer and use it in GitHub Desktop.
Save shuji/2333358 to your computer and use it in GitHub Desktop.
example - "10,12-14,15-".split
import java.util.regex.Matcher
"10,12-14,15-".split(',').each {
switch(it) {
case ~/(\d+)\-(\d+)/:
def from = Matcher.lastMatcher[0][1].toInteger()
def to = Matcher.lastMatcher[0][2].toInteger()
println "from=${from}, to=${to}"
break
case ~/(\d+)\-/:
def from = Matcher.lastMatcher[0][1].toInteger()
println "from=${from}"
break
case ~/(\d+)/:
def line = Matcher.lastMatcher[0][1].toInteger()
println "line=${line}"
break
default:
pritnln '??'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment