Regular Expressions 101

Community Patterns

Match many cases of 8601

1

Regular Expression
Java 8

"
^(?<year>\d{4})[-\/](?<month>0[1-9]|1[0-2])[-\/](?<day>0[1-9]|[1-2][0-9]|3[0-1])(?:[T\s](?:(?<hour>0[0-9]|1[0-9]|2[0-4]):(?<minute>\d{2}):(?<second>\d{2})(?:\.(?<nano>\d+))?))?(?:(?<offset>[Zz]|(?:[+-])(?:[01]\d|2[0-3])(?::?[0-5]\d)?)?)$
"
gm

Description

This is still a working in progress

Need to do Unit Tests and search for more use cases

Match partial cases of 8601 such as:

  • missing offset
  • missing time
  • only date and offset
  • nano present or not (and being from 1 digit to 9 digits)

Also properly captures the data by capturing only: year, month, date, hour, minute, second, nano and offset (be it 'Z' or '+02:00' or' +0200')

Submitted by jpmand - 8 months ago (Last modified 8 months ago)