Skip to content

Instantly share code, notes, and snippets.

View wheelerlaw's full-sized avatar
💻
Probably writing code

Wheeler Law wheelerlaw

💻
Probably writing code
  • Chicago
  • 05:43 (UTC -06:00)
View GitHub Profile
## Obtain Token and Invoke Service
@EwanDawson
EwanDawson / regex-capture.groovy
Created April 17, 2012 16:09
Idiomatic regex group capturing in Groovy
// Using Matcher object returned by =~ operator
matcher = "Hello world v1.01" =~ /.* v(\S*)/
if (matcher.matches()) version = matcher[0][1]
assert version == "1.01"
// We can make this a little tidier using the 'with' method
version = ("Hello world v1.01" =~ /.* v(\S*)/).with { matches() ? it[0][1] : null }
assert version == "1.01"