Skip to content

Compiled regex objects in Query objects and the likes. #1103

@sanderfoobar

Description

@sanderfoobar
@router.get("/foobar", response_model=FooBarModel, status_code=200)
async def foobar(
    addition: str = Query(None, regex="\w+", description="some regex")
):
    pass

Would be nice if you could pass compiled regex objects to regex= parameter of Query, e.g: regex=re.compile(r"\w+").

https://github.com/tiangolo/fastapi/blob/025b38df40a18f94322fab445aee13024fe783da/fastapi/param_functions.py#L51

Possibly also for Path, Cookie, Form, File.

re.compile("\w+").pattern == "\\w+"
True

Why? So I don't have to write regex=MyRegex.pattern (being pedantic :-P)

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