-
-
Notifications
You must be signed in to change notification settings - Fork 382
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
?
in optional capture group isn't connected to group in output - named param
#287
Comments
Your fix only works accidentally because of #286. You should be escaping the inner parentheses. This isn’t a bug, just confusion on what is happening here - your first closing paren is closing the entire regex. What version are you using? |
Based on your outputs I’m fairly sure you’re testing with an unsupported version. |
It looks like Sorry for not checking versions. I assumed they were using a relatively right version given their big note about using this project under https://expressjs.com/en/guide/routing.html#route-paths and even this project readme links the live demo as the Express route tester.
Trying to escape the inner parenthesis has no effect on getting the right grouping with that version
Edit: Actually in It looks like the new mission is to post the issue in the Thanks for checking in on all of this! |
You probably want to try using the Express 5 release instead of Express 4 for an updated |
@dougwilson It looks like Express 5 (plus it's still in beta) doesn't use
With the latest
@blakeembrey What's the correct input I should expect to work? What version are you seeing it work in? |
The latest version is the correct behavior. |
To be clearer too, none of these examples have extra backslashes either. I think you’re interpreting the JS strings incorrectly. Since backslash is a special character you need another backslash to escape it. That’s why you’re seeing two when viewed as a string. |
@blakeembrey Can you give an example? I feel like I've tried all of variations for escaping the backslash (even 3 and 4 backslashes now) |
You aren’t allowed to use capturing groups within the regex section of the string for this library. It’s exactly what the latest version says which I meant is the correct behavior. I’m kind of guessing that’s what you’re trying to do? |
You can make it a non-capturing group if that’s acceptable for your use case. |
Thanks for noting this caveat! Works perfect in
And to note how it behaves in other versions (relevant for
|
Expected goal
The goal is to make a route where
foo
is optional betweenA
andB
:Bug
But using the following input gives a flawed output regex that groups
A
andfoo
together in the optional capture group.Input:
Output ❌:
Workaround
Workaround input is to wrap the optional capture group in another capture group:
Input:
Output (works sufficiently) ✅:
Input and output tested on http://forbeslindesay.github.io/express-route-tester/
The text was updated successfully, but these errors were encountered: