Created
April 7, 2018 10:17
-
-
Save paul-dest/a3303a6f0156eb2423631988827897f4 to your computer and use it in GitHub Desktop.
Groovy: a short way to access captured groups after a match test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.regex.Matcher as M | |
static M getM() { M.lastMatcher } | |
if ("2018-4-7" ==~ /(\d{1,4})-(\d{1,2})-(\d{1,2})/) | |
println "day ${m[0][3]}, month ${m[0][2]}, year ${m[0][1]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apparently, GitHub's code highlighting stylesheet does not support Groovy's "as X" extension of import.