eu-dcc-business-rules icon indicating copy to clipboard operation
eu-dcc-business-rules copied to clipboard

Use named capturing groups for regular expression

Open ubamrein opened this issue 3 years ago • 2 comments

The regular expression used for parsing date times contains a lot of enumerated capturing groups

https://github.com/ehn-dcc-development/dgc-business-rules/blob/88a6e3bae58b8ff7cede2677982ee4fa771ee405/certlogic/certlogic-kotlin/src/main/kotlin/eu/ehn/dcc/certlogic/JsonDateTime.java#L37

I would suggest to change that to named capturing groups, to implicitly state the semantics of them and minimize errors when potentially adding or removing capturing groups.

Note, that https://github.com/ehn-dcc-development/dgc-business-rules/issues/31. mentions a missing ? after the timezone capturing group, which is not included here.

^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})T(?<timeHour>\d{2}):(?<timeMinute>\d{2}):(?<timeSecond>\d{2})(?<fractional>\.\d+?)?(?<timezone>Z|(?<offsetHour>[+-]\d{2}):?(?<offsetMinute>\d{2})?)$

ubamrein avatar Jul 01 '21 05:07 ubamrein

Note that the java.util.regex.Pattern class does not support underscores in capturing group names: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#cg

M-Wong avatar Jul 01 '21 06:07 M-Wong

Another concern is that I'd like to align the Kotlin/Java/JVM-implementation with the {Type|Java}Script one: https://github.com/ehn-dcc-development/dgc-business-rules/blob/main/certlogic/certlogic-js/src/internals.ts#L45

I'll keep the issue, but it's not very high-prio, so I'll have to see when I get around to it.

dslmeinte avatar Jul 01 '21 07:07 dslmeinte

(Cleaning up issues.)

dslmeinte avatar Feb 16 '23 10:02 dslmeinte