Pattern - sgpinkus/json-schema GitHub Wiki
THIS WIKI IS OBSOLETE. PLEASE SEE THE NEW JSON-SCHEMA-ORG/JSON-SCHEMA-SPEC REPOSITORY.
A string instance is valid against pattern if and only if this keyword's value, which is a regular expression, matches the instance successfully.
NOTE: as per the actual definition, regular expression matching succeeds if it matches anywhere in the input. Many programming languages (Java, Python, others) have misnamed .matches or .match functions/methods which anchor regexes (either at the beginning, at the end, or both).
The value of this keyword MUST be a string. The string value MUST be a valid ECMA 262 regular expression.
See here for the ECMA 262 regular expression language.
(Note: this example is of course limited; regular expressions are an entire field of study by themselves which has spawned many books. If any, I'd recommend this one.)
Given this schema:
{
"pattern": "[Ss]mith\\\\b"
}
the following values are valid:
- "My blacksmith produces excellent steel";
- "My name is John Smith, nice to meet you";
the following values are not valid:
- "I am no good at smithing, I'm afraid";
- "We visit the Smithes today".