/ / Come abbinare due barre nel mio schema rexex: regex, google-analytics

Come abbinare due barre nel mio pattern rexex - regex, google-analytics

Sto cercando di trovare un'espressione regolare che raggiungerà separatamente la seconda barra come l'ultimo carattere (ad es. /s/test/xxxx/)

Tuttavia, non posso garantire che gli URL di cui sopra includano qualcos'altro oltre alla conclusione con una barra aggiuntiva, ad es. /s/test/xxxx/yyyy/

Se uso qualcosa del genere

^/s/(.*?)/(.*?)/

Quello sopra funziona benissimo per il primo modello, ma non appena aggiungo il $ per assicurarsi che l'ultima (e la seconda) barra finale sia l'ultimo carattere in cui entrambi i casi seguenti sono abbinati.

/s/test/xxxx/
/s/test/xxxx/yyyy/

Cosa c'è che non va?

Grazie

risposte:

0 per risposta № 1

È possibile utilizzare una classe di caratteri negata:

^/s/[^/]+/[^/]+/$

Spiegazione della regex (cortesia Questo):

NODE                     EXPLANATION
--------------------------------------------------------------------------------
^                        the beginning of the string
--------------------------------------------------------------------------------
/s/                      "/s/"
--------------------------------------------------------------------------------
[^/]+                    any character except: "/" (1 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
/                        "/"
--------------------------------------------------------------------------------
[^/]+                    any character except: "/" (1 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
/                        "/"
--------------------------------------------------------------------------------
$                        before an optional n, and the end of the
string

0 per risposta № 2

Puoi usare questa regex:

^/[^/]+/[^/]+/[^/]+/?$