Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fun with regex group names
import java.util.regex.Matcher
import java.util.regex.Pattern
Map splitLabel(String label) {
Pattern labelPattern = Pattern.compile('(?<column>^[A-Za-z]+)(?<side>\\d)(?<row>\\d+$)')
Matcher labelMatcher = labelPattern.matcher(label)
labelMatcher.find()
String columnLabel = labelMatcher.group("column")
Integer sideLabel = Integer.parseInt(labelMatcher.group("side"))
Integer binNumber = Integer.parseInt(labelMatcher.group("row"))
return [
side: sideLabel,
column: columnLabel,
bin: binNumber
]
}
println splitLabel('AA101')
println splitLabel('X11')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.