Skip to content

Instantly share code, notes, and snippets.

@paul-dest
Created April 7, 2018 10:17
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 paul-dest/a3303a6f0156eb2423631988827897f4 to your computer and use it in GitHub Desktop.
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
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]}"
@paul-dest
Copy link
Author

Apparently, GitHub's code highlighting stylesheet does not support Groovy's "as X" extension of import.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment