Skip to content

regex named segments #14

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

Closed
ozmuir opened this issue Jul 23, 2015 · 5 comments
Closed

regex named segments #14

ozmuir opened this issue Jul 23, 2015 · 5 comments

Comments

@ozmuir
Copy link

ozmuir commented Jul 23, 2015

It'll be a nice little addition to have named regex segments, for ex.
new UrlPattern(/^\/user\/(\d+)\//i, ["user_id"])

@snd
Copy link
Owner

snd commented Jul 23, 2015

good idea !
i'll implement it.

what do you think about the following edge case behaviour ?

if there are more groups in the regex than there are names in the array that is the second argument:
ignore captured values for the remaining superfluous groups.

if there are less groups in the regex than there are names in the array that is the second argument:
ignored the remaining superfluous names.

shouldn't break backwards compatibility - which is nice.

@ozmuir
Copy link
Author

ozmuir commented Jul 23, 2015

👍 however don't you think it'll be more expressive to not just ignore but:

  • if there are more groups in regex, then resulting object will take additional numeric keys with the values of corresponding regex group;
  • if there are less groups in regex, then excessive keys get undefined?
    😉

@snd
Copy link
Owner

snd commented Jul 29, 2015

i now think we should consider it a user error if the number of groups and names in the array don't match up.

i would like to throw an error in such cases to notify the user of bad usage.
better to blow up on that set of user bugs that to let them go unnoticed.

i might use http://stackoverflow.com/a/16046903 to detect the number of groups and be able to check for such errors as soon as possible i.e. on pattern creation and not on match (callsites of .match tend to be far away from pattern creation).

what do you think ?

@ozmuir
Copy link
Author

ozmuir commented Jul 29, 2015

sure, sounds good.

@snd
Copy link
Owner

snd commented Aug 19, 2015

@snd snd closed this as completed Aug 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants