Skip to content

✨ Proposal: add regex lookbehind support (ES2018) #1591

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

Closed
ryanblock opened this issue Mar 10, 2025 · 1 comment
Closed

✨ Proposal: add regex lookbehind support (ES2018) #1591

ryanblock opened this issue Mar 10, 2025 · 1 comment
Labels
proposal Initial discussion of a new idea. A project will be created once a proposal document is created.

Comments

@ryanblock
Copy link

Describe the inspiration for your proposal

Authoring JSON Schemas that utilize regex patterns for properties where we do not want a string to end in a certain character (such as - or _); for this, negative lookbehinds are a highly useful tool.

Describe the proposal

As of today, while JSON Schema supports lookahead regex patterns, it does not appear to support lookbehinds. See:

Lookbehind was introduced in ES2018 and now enjoys broad support:

This seems like a natural addition!

Describe alternatives you've considered

No response

Additional context

Previously raised or mentioned in:

@ryanblock ryanblock added the proposal Initial discussion of a new idea. A project will be created once a proposal document is created. label Mar 10, 2025
@jdesrosiers
Copy link
Member

JSON Schema already defines the regular expression dialect to be defined by ECMA 262 [Reference], which means it already does support lookbehind. 🎉

However, JSON Schema is not just for JavaScript. It's not reasonable to expect implementations in Java, C#, Python, Ruby, etc to perfectly match JavaScript's regex dialect. That's why we suggest (not require) schema authors limit their use of regex features to what is likely to be supported by most regex engines. It would be impractical to expect implementations in non-JavaScript languages to implement ECMA-262 regular expression to comply with the spec. Implementations are going to use the regex engines available to them in the language they're implementing in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Initial discussion of a new idea. A project will be created once a proposal document is created.
Projects
None yet
Development

No branches or pull requests

2 participants