In several cases, I needed to fix the "day" part of the date, formatted as follows: "YYYY/DD/MM"My question is whether it was better to use a regular expression with a capture group vs. just calling split on "/" and just taking the second element in the array?
Functionally, I understand that BOTH gets the same result.
In my opinion, I understand that they use the regex mechanism under the hood, and that in most cases I just drop the array after reading the value for the day using split. But technically, I do the same after reading from the object Match. I am looking to see if there are any corner cases and trade-offs that I have to consider, but I do not? (In addition, readability ... the “split” clearly wins there ...)
=== EDIT === By API I am limited to Groovy 1.5.0 for silly reasons.
To clarify edmastermind solution:
def nowCal = Calendar.instance
def currentDay = nowCal.get(Calendar.DAY_OF_MONTH)
source
share