Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regex for supported inputs #46

Open
danieleades opened this issue Nov 2, 2023 · 2 comments
Open

regex for supported inputs #46

danieleades opened this issue Nov 2, 2023 · 2 comments

Comments

@danieleades
Copy link

is there a regex that can be used to check whether the provided string is in a format that can be parsed by this library?

for the purposes of using in a jsonschema

@sunshowers
Copy link

For durations, here's what I came up with (newlines for clarity, remove them from the final regex):

(?:\d+\s*(?:years|year|y))?\s*
(?:\d+\s*(?:months|month|M))?\s*
(?:\d+\s*(?:weeks|week|w))?\s*
(?:\d+\s*(?:hours|hour|hr|hrs|h))?\s*
(?:\d+\s*(?:minutes|minute|min|mins|m))?\s*
(?:\d+\s*(?:seconds|second|sec|secs|s))?\s*
(?:\d+\s*(?:millis|msec|ms))?\s*
(?:\d+\s*(?:usec|us))?\s*
(?:\d+\s*(?:nanos|nsec|ns))?\s*

This isn't perfect, though, because it doesn't reject empty strings.

@danieleades
Copy link
Author

Ideally the regex would be a constant exported by the library itself.

I wonder if the maintainers would be open to a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants