tips – Not great at regexs. Trying to code-golf this beast of a regex WITHOUT using string replacement (for G-Zip purposes)

Here it is:

^(?:(?:(?:(\d+(?:\.\d+)?)?(?::|\.|,))?(\d+)?(?::|\.|,))?(\d+(?:\.\d+)?)?(?:(?:\.|:|,)(\d+(?:\.\d+)?)?)?)?(?:,|,(?:(?:(\d+(?:\.\d+)?)?(?::|\.|,))?(\d+(?:\.\d+)?)?(?::|\.|,))?(\d+(?:\.\d+)?)?(?:(?:\.|:|,)(\d+(?:\.\d+)?)?)?)?$

What am I doing:

Matching any ranged timestamp (HH:MM:SS:MS,HH:MM:SS:MS) with a few “leniences”

  1. Any length digits – we do NOT need restrictions to strict 24 hr, 59 min / sec, \d{1,9} milliseconds. I do automatic conversions for this and shift in my code allowing lenience
  2. Likewise, I’m not strict on requiring the : as the delimiter. It can be one of:
    : OR , OR . OR |
  3. Similarly, they don’t NEED to strictly put digits into any specific slot. They can be blank. :MM:SS:MS, HH::SS:MS, etc in all combinatorial possibilites

Yes, I know that I COULD do simple string replacement / injections given how markedly repetitive this is. Thing is, in most coding languages G-Zip compresses better w/o this.

So, that’s it.

I need:

Each capture group (HH:MM:SS:MS) for EACH range. I am mapping these from captured groups -> milliseconds conversion -> human readable time (e.g. – 4 hours, 15 minutes, 30 seconds, 4234 milliseconds, 300 nanoseconds, …)

Language: JavaScript

Read more here: Source link