Express Syntax for Mustermann
This gem implements the express
pattern type for Mustermann. It is compatible with Express and pillar.js.
Overview
Supported options:
capture
, except
, greedy
, space_matches_plus
, uri_decode
, and ignore_unknown_options
.
External documentation: path-to-regexp, live demo
Express patterns feature named captures (with repetition support via suffixes) that start with a colon and can have an optional regular expression constraint or unnamed captures that require a constraint.
require 'mustermann/express'
Mustermann.new('/:name/:rest+', type: :express).params('/a/b/c') # => { name: 'a', rest: 'b/c' }
pattern = Mustermann.new('/:name', type: :express)
pattern.respond_to? :expand # => true
pattern.(name: 'foo') # => '/foo'
pattern.respond_to? :to_templates # => true
pattern.to_templates # => ['/{name}']
Syntax
Syntax Element | Description |
---|---|
:name | Captures anything but a forward slash in a semi-greedy fashion. Capture is named name. Capture behavior can be modified with capture and greedy option. |
:name+ | Captures one or more segments (with segments being separated by forward slashes). Capture is named name. Capture behavior can be modified with capture option. |
:name* | Captures zero or more segments (with segments being separated by forward slashes). Capture is named name. Capture behavior can be modified with capture option. |
:name? | Captures anything but a forward slash in a semi-greedy fashion. Capture is named name. Also matches an empty string. Capture behavior can be modified with capture and greedy option. |
:name(regexp) | Captures anything matching the regexp regular expression. Capture is named name. Capture behavior can be modified with capture. |
(regexp) | Captures anything matching the regexp regular expression. Capture is named splat. Capture behavior can be modified with capture. |
/ | Matches forward slash. Does not match URI encoded version of forward slash. |
any other character | Matches exactly that character or a URI encoded version of it. |