Ich versuche, ein Unterverzeichnis in einer URL übereinstimmen, die nach einem bestimmten Verzeichnis kommt:Javascript Regex ein Unterverzeichnis in URL ersetzen
dann ein Verzeichnis auf den gefundenen String anhängen.
/applications/app1
sollte /applications/app1/beta
/applications/app2/
sollte /applications/app2/beta/
/applications/app2/settings
sollte /applications/app2/beta/settings
/applications/app3?q=word
sollte /applications/app3/beta?q=word
Ich schrieb dieses:
path = path.replace(/(\/applications\/(.*)(\/|\s|\?))/, '$1/beta');
Aber funktioniert nicht, wenn der app-name am Ende der Zeichenfolge ist.
Hinweis: ich nicht den Namen der Anwendung habe ich weiß nur, dass es /applications/
Achten Sie darauf, dass Sie nach dem Ersetzen von '/ applications/app2/settings' durch'/applications/app2/beta/settings leicht in den Abgrund fallen können, indem Sie '/ applications/app2/beta/settings' durch ersetzen '/ applications/app2/beta/beta/settings', die zu'/applications/app2/beta/beta/beta/settings' werden ... – zvone