Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Exact Match by non capturing group but allow wildcard for subsegments #223

Copy link
Copy link
@janus-reith

Description

@janus-reith
Issue body actions

I'm trying to rewrite non-localized paths (e.g /page1) to localized ones (/de/page1) and therefore I'm seeking help to get the following to work:

  • "/de" or "/en" should NOT be matched

  • "/de/anything" or "/en/anything" should NOT be matched

  • "/test" or "/test/anything" should be matched

  • "/deno" or "/end" should be matched

With my current implementation which is based on:

"/:test((?!login)[^/]+)",

I can get the first 3 of 4 requierements, but can't prevent "de" from also matching "deno".
It seems like instead of allowing any chars which are not "/" after the lang segment, I would need a solution which allows either an exact match or a wilcard which must be preceded by another "/". (So both /de and /de/anything would be covered).

Segmenting these values any further is not a requierement as I'm taking req.url as a whole and only prepend the locale.

This sandbox should probably make it easy to get what I mean:
https://codesandbox.io/s/path-to-regexp-demo-c9efk?file=/src/index.js
(Result is in the console)

I got a bit stuck here, and any help is appreciated, thank you! :)

Vadorequest and ownerni

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.