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.

I was aided in my quest primarily by an excellent post from Ted Nalied.

Here’s the script and a demo of some of the things you can do:

Date manipulation with Regex in Groovy

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:


About this entry