question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clarification on pattern regex literals

See original GitHub issue

The specification for pattern says

This string SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect

I think this is extracted verbatim from the JSON Schema validation draft as per #880

However, the section of ECMA262 linked to describes the regular expression literal i.e. / RegularExpressionBody / RegularExpressionFlags so it is unclear whether “valid regular expression” means the body or the literal.

There are no example usages of regex patterns in the OAS 3.0.2 document that I can see. However, another example of patterns used in OpenAPI that I have found does not include the / characters around the regex e.g.:

I think it is unclear from the specification (either OAS or JSON schema validation) whether the pattern field is expected to be a complete ECMA 262 regular expression literal, including the / characters and optionally including flags, or whether it is saying that only a regular expression body is expected.

Tooling behaviour seems a little inconsistent on this too, so I think a clarification would be useful to help tooling developers know which of these 3 types of pattern values should be supported:

  1. myregexbody
  2. /myregexbody/
  3. /myregexbody/myregexflags

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
handrewscommented, Aug 7, 2019

@ricellis it is definitely 1. myregexbody. The correct reference is ECMA 262 Annex A.7, “Regular Expressions”, although given that that section is informative rather than normative there might be some complications on exactly how to cite that. Referencing RegularExpressionBody for clarity would probably be a good idea.

This should really be filed on the JSON Schema spec repo.

I’ll try to remember to clarify that i

0reactions
philsturgeoncommented, Jan 9, 2020

This was fixed in #1977 so we can close this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Regular expressions - JavaScript - MDN Web Docs
Simple patterns are constructed of characters for which you want to find a direct match. For example, the pattern /abc/ matches character ...
Read more >
An introduction to regular expressions - O'Reilly
Literals and special characters. A regular expression matches a broad or specific text pattern, and is strictly read left-to-right.
Read more >
Regular Expressions And Template Literals
A different take on generating Regular Expressions using some of JavaScript's newer patterns. This is an experiment.
Read more >
Patterns and flags - The Modern JavaScript Tutorial
A regular expression (also “regexp”, or just “reg”) consists of a pattern and optional flags. There are two syntaxes that can be used...
Read more >
Regular expressions quick reference - Computer Hope
Regular expressions (shortened as "regex") are special strings representing a pattern to be matched in a search operation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found