KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to get an optional lookahead but am having problems where as soon as I make it optional (add a ? after it), it no longer matches even when the data is there. As a brief summary, I'm trying to pull specific querystring params out of a URI. Example: /.*foo.html\??(?=.*foo=([^\&]+))(?=.*bar=([^\&]+))/ .exec( 'foo.html?foo=true&bar=baz' ) I'll break that out a bit: .*foo.html\?? // filename == `foo.html` + '?' (?=.*foo=([^\&]+)) // find "foo=...." parameter, store the value (?=.*bar=([^\&]+)) // find "bar=...." parameter, store the value The above example works perfectly under the condition that both foo and bar exist as parameters in the querystring. The issue is that I'm trying to make these optional, so I changed it to: /.*foo.html\??(?=.*foo=([^\&]+))?(?=.*bar=([^\&]+))?/ ↑ ↑ Added these question marks ─┴──────────────────┘ and it no longer matches any parameters, though it still matches foo.html . Any ideas?
Tags (comma-separated)
Save Edits
Cancel