Skip to content

Instantly share code, notes, and snippets.

@aaronzirbes
Created December 13, 2018 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronzirbes/e4817ae2447d9e50444f6cef7bd01bac to your computer and use it in GitHub Desktop.
Save aaronzirbes/e4817ae2447d9e50444f6cef7bd01bac to your computer and use it in GitHub Desktop.
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