-2

I have a script which is grabbing the URL of a Google Compute Backend. I want to use RegEx to extract a small part of it, but keep getting caught up in the first match:

https://www.googleapis.com/compute/v1/projects/website-prod-1234/global/backendServices/website-prod-num-1111-backend
https://www.googleapis.com/compute/v1/projects/website-prod-1234/global/backendServices/website-prod-re-3724-backend
https://www.googleapis.com/compute/v1/projects/website-prod-1234/global/backendServices/website-prod-test-backend

In those examples, trying to extract the following parts:

num-1111
re-3724
test

This is my hack of an expression, but it gets caught up in the first occurrence of "website-prod-" and grabbing the whole half of the link. How can I make it start from the second part?

(?<=website-prod-).*(?=-backend)
Barmar
  • 741,623
  • 53
  • 500
  • 612

1 Answers1

0

Use:

(?<=website-prod-)[^/]*(?=-backend)

Using [^/] instead of . prevents this from matching across directory delimiters.

Barmar
  • 741,623
  • 53
  • 500
  • 612