Skip to content
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

Regex with starting optional group after forward slash gives error #70

Closed
clshortfuse opened this issue Feb 25, 2016 · 3 comments
Closed

Comments

@clshortfuse
Copy link

I'm using express which uses path-to-regexp for URL routing.

If I use the following regex:

'/(apple-)?icon-:res(\\d+)x\\2.png'

I get the following error:

Invalid regular expression: /^\/(?(?:([^\/]+?))-)?icon-(?:(\d+))x\2\.png\/?$/: Invalid group

Using escaped forward slash still gives an Invalid group error

Breaking it down to just

'/(apple-)?'

gives

/^\/(?(?:([^\/]+?))-)?\/?$/: Invalid group

My current workaround is to do the following:

'/?(apple-)?icon-:res(\\d+)x\\2.png'
@blakeembrey
Copy link
Member

Express.js uses a legacy version with legacy behaviour such as this, there's not anything that can be done, I don't think, other than updating Express.js.

@blakeembrey
Copy link
Member

Ah, even on the new version the regexp doesn't match properly because of the way you're doing an optional group. I'm going to reopen to support that on the stable branch, however I still don't believe there's anything that can be done on 0.1. For reference, this is the RegExp on 1.x:

/^(?:\/(apple-))?icon-(\d+)x2\.png(?:\/(?=$))?$/i

@blakeembrey blakeembrey reopened this Feb 26, 2016
@blakeembrey
Copy link
Member

@clshortfuse I suggest using a RegExp with you're on the current version of Express. I'm playing around with a patch for the current version of path-to-regexp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants