File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change
1
+ Document default ` regex ` anchoring semantics
Original file line number Diff line number Diff line change @@ -69,6 +69,23 @@ It has the following arguments:
69
69
JSON Schema
70
70
* ` regex ` : for string values, this adds a Regular Expression validation generated from the passed string and an
71
71
annotation of ` pattern ` to the JSON Schema
72
+
73
+ !!! note
74
+ * pydantic* validates strings using ` re.match ` ,
75
+ which treats regular expressions as implicitly anchored at the beginning.
76
+ On the contrary,
77
+ JSON Schema validators treat the ` pattern ` keyword as implicitly unanchored,
78
+ more like what ` re.search ` does.
79
+
80
+ For interoperability, depending on your desired behavior,
81
+ either explicitly anchor your regular expressions with `^`
82
+ (e.g. `^foo` to match any string starting with `foo`),
83
+ or explicitly allow an arbitrary prefix with `.*?`
84
+ (e.g. `.*?foo` to match any string containig the substring `foo`).
85
+
86
+ See [#1631](https://github.com/samuelcolvin/pydantic/issues/1631)
87
+ for a discussion of possible changes to *pydantic* behavior in **v2**.
88
+
72
89
* ` ** ` any other keyword arguments (e.g. ` examples ` ) will be added verbatim to the field's schema
73
90
74
91
Instead of using ` Field ` , the ` fields ` property of [ the Config class] ( model_config.md ) can be used
You can’t perform that action at this time.
0 commit comments