Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named regex segments? #56

Open
stoplion opened this issue Sep 8, 2020 · 0 comments
Open

Named regex segments? #56

stoplion opened this issue Sep 8, 2020 · 0 comments

Comments

@stoplion
Copy link

stoplion commented Sep 8, 2020

var UrlPattern = require("url-pattern")

Is there any way to enforce regex at a segment level?

I have a pattern for username with a @.

The current route matchers are failing with the @.

  var pattern = new UrlPattern(':username/:postID');
  pattern.match('@stoplion/123');

I think I can build the regex like this..

   var pattern = new UrlPattern(/@[a-z0-9][-a-z0-9]+)\/([a-z0-9][-a-z0-9]+)/, ['username', 'postIid']);

The URL itself is very hard to read, and I can't figure out what it is at a glance..

Is it possible to do something like this..
Where you can get the named segments, and then enforce a regex pattern

var pattern = new UrlPattern(':username/:postID', {
   username: /@[a-z0-9][-a-z0-9]+/
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant