8000 Clarify regex usage for constr in documentation · Issue #1396 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content

Clarify regex usage for constr in documentation #1396

@lmcnearney

Description

@lmcnearney

It might be helpful to clarify that the constr type validator's regex argument uses re.match() which only requires a partial match on the string. This personally bit me as I assumed the ^ and $ weren't required and put a length restriction in the expression but the field validated as the start of the string matched.

Updating the example in the documentation would probably cover it:

regex_str: constr(regex='^apple (pie|tart|sandwich)$')

Alternatively, it could use re.fullmatch() but that would change the behavior of the validator.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0