Last active
January 18, 2023 16:42
-
-
Save utkuozdemir/aff7a347f9759a07bcf231da3df591a0 to your computer and use it in GitHub Desktop.
JS regex to validate Go time.Duration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^[-+]?(((\d+(\.\d*)?|\d*(\.\d+)+)(ns|us|µs|ms|s|m|h))|0)+$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Matches all
parseDurationTests
andparseDurationErrorTests
in Go's standard test suite except the overflowing ones:https://regex101.com/r/xNTblv/2
Unicode flag (
/u
) must be used with the pattern for the µ character to be matched.