Skip to content

Named regex segments? #56

@stoplion

Description

@stoplion

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]+/
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions