comb
comb

Reputation: 473

Get website regex from a website link

if I have a website like: www.google.com/en/my-page/anotherpage

how is it possible that with reg-ex to get: /en/my-page ? I am using this reg-ex in the IIS?

So far I have done something similar to this:

    ^(?:\\.|[^/\\])*/((?:\\.|[^/\\])*)/

but it is returning /en/my-page/ and I want it to return /en/my-page

Upvotes: 0

Views: 100

Answers (3)

Ja͢ck
Ja͢ck

Reputation: 173642

You could use a look-ahead assertion to get rid of the last slash:

/\/.*(?=\/)/

Upvotes: 1

blackSmith
blackSmith

Reputation: 3154

In grep your regex is returning the string "www.google.com/en/". You can simply use the following regex if positive look behind is not mandatory :

(/[^/]+)+

Upvotes: 1

sp00m
sp00m

Reputation: 48837

This one should suit your needs:

^[^/]+(/.*)/[^/]+$

Regular expression visualization

Visualization by Debuggex.

The output your looking for is in the first captured group.

Demo on RegExr.

Upvotes: 0

Related Questions