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 lookahead/behind is not supported #31

Closed
robbyt opened this issue Sep 10, 2019 · 2 comments
Closed

Regex lookahead/behind is not supported #31

robbyt opened this issue Sep 10, 2019 · 2 comments
Labels

Comments

@robbyt
Copy link

robbyt commented Sep 10, 2019

I have a regex like this:

"pattern": "^(?!(foo-|bar)-)[a-z][a-z0-9]+$"

In this example, I need to make sure a string does not start with foo- or bar-.

When I use this library, I get the error:
"^(?!(foo-|bar-))[a-z][a-z0-9]+$" is not valid "regex", which is valid regex for JS-based schema validators, but fails with this implementation, because the regexp library from the Golang stdlib does not support the ?!() syntax.

More info here:
https://stackoverflow.com/questions/26771592/negative-look-ahead-go-regular-expressions

@santhosh-tekuri
Copy link
Owner

since it is not supported by golang stdlib, there is nothing much i can do.

but you can workaround this by using jsonschema not and having a pattern which checks that value starts with foo- or bar- say pattern: ^(foo-|bar-)

@handrews
Copy link

@robbyt the spec specifically does not require these sorts of advanced regexes to be supported: https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-4.3 primarily in order to ensure that what is required is likely to be supported in all languages/environments.

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