diff --git a/google/cloud/aiplatform/utils/__init__.py b/google/cloud/aiplatform/utils/__init__.py index 593222ed0a..def5b3b265 100644 --- a/google/cloud/aiplatform/utils/__init__.py +++ b/google/cloud/aiplatform/utils/__init__.py @@ -105,6 +105,10 @@ reservation_affinity_v1 as gca_reservation_affinity_v1, ) +_PROJECT_LOCATION_RE = re.compile( + r"^projects/(?P.+?)/locations/(?P.+?)(/|$)" +) + VertexAiServiceClient = TypeVar( "VertexAiServiceClient", # v1beta1 @@ -399,9 +403,7 @@ def extract_project_and_location_from_parent( Dict[str, str] A project, location dict from provided parent resource name. """ - parent_resources = re.match( - r"^projects/(?P.+?)/locations/(?P.+?)(/|$)", parent - ) + parent_resources = _PROJECT_LOCATION_RE.match(parent) return parent_resources.groupdict() if parent_resources else {}