Cloud Run Regex

Share on:

Cloud Run Regex

Normally when someone mentions regex its time to make a swift exit. Since I was working on a new project featuring Cloud Run I needed to face my fears. This is my story.

I can't do this:inline

Regex for the masses

Cloud Run has a defined url signature which is common across all deployments. If you need to check that this signature is valid, regex is a nice approach to perform this action.

A Cloud Run service url signature typically looks like the following:

1https://<serviceName>-<projectHash>-<region>.run.app

Therefore to use Regex on a Cloud Run url use the following Regex:

1((https?:\/\/)?[0-9a-z]*-[\-0-9a-z]*\.a\.run\.app)

Lets examine the above in a bit more detail:

Section Description
https?://) Ensure the prefix uses HTTPS:\\
[0-9a-z] Accept characters 0-9 and a-z
.a Accept the .a
.run Accept the .run
.app Accept the .app

NOTE: In the above I repeat the character section to capture both sections i.e. serviceName + projectHash

Life has never been this good:inline

Regex is something I definitely need to practice in order to get a better understanding of how it works. Maybe you are in the same situation, in which case, I hope this short blog post helps.