Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get wildcard value

See original GitHub issue

Firstly, lovely little router this but one thing I’m not clear on. Is there a way in the handler, to get the value that a wildcard matched on. For example,

const router = Router()
router.get('/maps/tiles/vector/*', vectorTilesHandler)
router.get('/maps/tiles/static/*', staticTilesHandler)
router.get('/maps/packs/vector/*', vectorPacksHandler)
router.get('/maps/packs/static/*', staticPacksHandler)

I’d like to get the whole wildcard value in the handler. I can get the full url, but then that means I need to remove the host and duplicate the initial piece of path so I can strip that off the string.

Likewise I can’t use parameters because you can’t have a greedy parameter that takes all segments. The reason I need the wildcard is so i can proxy it as is (in these cases).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

R167commented, Mar 19, 2021

@kwhitley Here’s an example of how Express (JS) and Sinatra (Ruby) handle unnamed wildcards:

From the docs, they state Express (v4) takes the approach of making these index based on params. For example, for the path /file/*, express exposes the splat parameter at req.params[0] (express req.params)

When you use a regular expression for the route definition, capture groups are provided in the array using req.params[n], where n is the nth capture group. This rule is applied to unnamed wild card matches with string routes such as /file/*:

// GET /file/javascripts/jquery.js
// => 'javascripts/jquery.js'

Alternatively, the Ruby library mustermann used by sinatra uses the default name “splat”, so you can get the wildcard capture group at params["splat"].

pattern ='/:prefix/*.*')
pattern.params('/a/b.c') # => { "prefix" => "a", splat => ["b", "c"] }

Hope that’s useful!

kwhitleycommented, Mar 29, 2021

Thanks for understanding! When I get some free time this week, I’ll try to take a stab at a splat enabled wrapper! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get only wild card value using regular expression
This should do it : (DEMO) string input = "Book_1234_ABC"; MatchCollection matches = Regex.Matches(input, @"_([A-Za-z0-9]*)"); foreach ...
Read more >
Examples of wildcard characters - Microsoft Support
Wildcards are special characters that can stand in for unknown characters in a text value and are handy for locating multiple items with...
Read more >
Wildcard Function (GNU make)
$(wildcard pattern …) This string, used anywhere in a makefile, is replaced by a space-separated list of names of existing files that match...
Read more >
Excel Wildcard Characters - Why Aren't You Using These?
You can use the asterisk (*) wildcard character in data filter to get a list ... Partial look-up is needed when you have...
Read more >
SQL Wildcard Characters - W3Schools
CustomerID CustomerName ContactName Address 1 Alfreds Futterkiste Maria Anders Obere Str. 57 2 Ana Trujillo Emparedados y helados Ana Trujillo Avda. de la Constitución... 3 Antonio...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found