Groovy script demonstrating Regular Expressions to manipulate Dates
I wanted to manipulate a Date String of the format “Thu, 1/4/10” and manipulate it into 20100401 so I can sort the date easily.
I thought I’d be able to do this using named back references in Groovy. I didn’t see how to do this, but because Groovy has closures I was able to come up with an elegant equivalent solution.
Here’s the script and a demo of some of the things you can do:
The commented out line will produce the same output as the line above in this example.
A few other links that I found useful when creating this post were:
- Formatting a Number Using a Custom Format
- ParseInt example
- Groovy Series on Regex on Snipplr: 1 2 3.
- Page 83 of GinA
- Groovymag Jan 2009 issue