99
1010from ..catalog import CUSTOM_SCHEMA_NAMES , SCHEMA_CATALOG
1111from ..checker import SchemaChecker
12- from ..formats import KNOWN_FORMATS , RegexVariantName
12+ from ..formats import KNOWN_FORMATS
1313from ..instance_loader import InstanceLoader
1414from ..parsers import SUPPORTED_FILE_FORMATS
15+ from ..regex_variants import RegexImplementation , RegexVariantName
1516from ..reporter import REPORTER_BY_NAME , Reporter
1617from ..schema_loader import (
1718 BuiltinSchemaLoader ,
@@ -68,10 +69,11 @@ def pretty_helptext_list(values: list[str] | tuple[str, ...]) -> str:
6869 date, date-time, email, ipv4, ipv6, regex, uuid
6970
7071\b
71- For the "regex" format, there are multiple modes which can be specified with
72- '--format-regex':
73- default | check that the string is a valid ECMAScript regex
74- python | check that the string is a valid python regex
72+ For handling of regexes, there are multiple modes which can be specified with
73+ '--regex-variant':
74+ default | use ECMAScript regex syntax (via regress)
75+ nonunicode | use ECMAScript regex syntax, but in non-unicode mode (via regress)
76+ python | use python regex syntax
7577
7678\b
7779The '--builtin-schema' flag supports the following schema names:
@@ -138,11 +140,18 @@ def pretty_helptext_list(values: list[str] | tuple[str, ...]) -> str:
138140)
139141@click .option (
140142 "--format-regex" ,
143+ hidden = True ,
144+ help = "Legacy name for `--regex-variant`." ,
145+ default = None ,
146+ type = click .Choice ([x .value for x in RegexVariantName ], case_sensitive = False ),
147+ )
148+ @click .option (
149+ "--regex-variant" ,
141150 help = (
142- "Set the mode of format validation for regexes. "
143- "If `--disable-formats regex` is used, this option has no effect ."
151+ "Name of which regex dialect should be used for format checking "
152+ "and 'pattern' matching ."
144153 ),
145- default = RegexVariantName . default . value ,
154+ default = None ,
146155 type = click .Choice ([x .value for x in RegexVariantName ], case_sensitive = False ),
147156)
148157@click .option (
@@ -230,7 +239,8 @@ def main(
230239 no_cache : bool ,
231240 cache_filename : str | None ,
232241 disable_formats : tuple [list [str ], ...],
233- format_regex : t .Literal ["python" , "default" ],
242+ format_regex : t .Literal ["python" , "nonunicode" , "default" ] | None ,
243+ regex_variant : t .Literal ["python" , "nonunicode" , "default" ] | None ,
234244 default_filetype : t .Literal ["json" , "yaml" , "toml" , "json5" ],
235245 traceback_mode : t .Literal ["full" , "short" ],
236246 data_transform : t .Literal ["azure-pipelines" , "gitlab-ci" ] | None ,
@@ -243,6 +253,8 @@ def main(
243253) -> None :
244254 args = ParseResult ()
245255
256+ args .set_regex_variant (regex_variant , legacy_opt = format_regex )
257+
246258 args .set_schema (schemafile , builtin_schema , check_metaschema )
247259 args .set_validator (validator_class )
248260
@@ -257,7 +269,6 @@ def main(
257269 else :
258270 args .disable_formats = normalized_disable_formats
259271
260- args .format_regex = RegexVariantName (format_regex )
261272 args .disable_cache = no_cache
262273 args .default_filetype = default_filetype
263274 args .fill_defaults = fill_defaults
@@ -318,6 +329,7 @@ def build_checker(args: ParseResult) -> SchemaChecker:
318329 instance_loader ,
319330 reporter ,
320331 format_opts = args .format_opts ,
332+ regex_impl = RegexImplementation (args .regex_variant ),
321333 traceback_mode = args .traceback_mode ,
322334 fill_defaults = args .fill_defaults ,
323335 )
0 commit comments