Elre
Elre

Reputation: 21

Using Re2 regex to pull content between 2 brackets in a specific location on the string

I wondered if anyone could help me, I'm trying to pull the content after "en" and only between the following brackets /en/[here]/ so in the below example, it should return "about".

/content/web/gx/en/about/analyst-research/archive/market

All the URLs have the same pattern at the beginning (i.e. /content/web/gx/en), I'm actually using Google sheets for this, which uses Re2. I've tried various approaches, but I haven't used regex much, so struggling with this. Any help welcome.

Thanks

Upvotes: 0

Views: 556

Answers (2)

Gustav Rasmussen
Gustav Rasmussen

Reputation: 3971

The following pattern can be used to extract your text:

/content/web/gx/en/(\w+).*

See the full solution with capturing the group: https://regex101.com/r/C9S7P4/2

Upvotes: 0

totok
totok

Reputation: 1500

You can use this regex :

en\/([^\/]*)\/

For /content/web/gx/en/about/analyst-research/archive/market it will return about.

You can test it here

Upvotes: 1

Related Questions