santhosh-tekuri/jsonschema

Regex lookahead/behind is not supported

Closed this issue · 2 comments

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

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-)

@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.