From dc10b81d05fc4438038d74543333661073bf7c8a Mon Sep 17 00:00:00 2001
From: pylounge <78209508+pylounge@users.noreply.github.com>
Date: Fri, 26 Aug 2022 16:46:22 +0300
Subject: [PATCH] =?UTF-8?q?=E2=99=BB=20Simplify=20internal=20RegEx=20in=20?=
 =?UTF-8?q?`fastapi/utils.py`=20(#5057)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
---
 fastapi/utils.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fastapi/utils.py b/fastapi/utils.py
index b7da3e484..0ced01252 100644
--- a/fastapi/utils.py
+++ b/fastapi/utils.py
@@ -140,14 +140,14 @@ def generate_operation_id_for_path(
         stacklevel=2,
     )
     operation_id = name + path
-    operation_id = re.sub("[^0-9a-zA-Z_]", "_", operation_id)
+    operation_id = re.sub(r"\W", "_", operation_id)
     operation_id = operation_id + "_" + method.lower()
     return operation_id
 
 
 def generate_unique_id(route: "APIRoute") -> str:
     operation_id = route.name + route.path_format
-    operation_id = re.sub("[^0-9a-zA-Z_]", "_", operation_id)
+    operation_id = re.sub(r"\W", "_", operation_id)
     assert route.methods
     operation_id = operation_id + "_" + list(route.methods)[0].lower()
     return operation_id