Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matching one or another word in AngularJS ui-router

Using AngularJS + ui-router, I need to match a url with one of two words:

i.e. /oneWord/... or /secondWord...

The routing and controllers are nearly identical, so I want to avoid duplicating code.

However, using a regex I'm used to, doesn't work where regular expressions should work:

url: '/{type:(oneWord|secondWord)}/:group',

However, it throws an error:

Unbalanced capture group in route '/{type:(oneWord|secondWord)}/:group'

A regex should work though, because this works fine:

url: "/{page:[0-9]{1,8}}"

I know that (oneWord|secondWord) is a valid regex, so what have I missed?

like image 538
helion3 Avatar asked Feb 22 '14 00:02

helion3


1 Answers

According to the documentation you should not use capturing parentheses in your regex patterns.

This should work: url: '/{type:(?:oneWord|secondWord)}/:group'

like image 192
rtcherry Avatar answered Oct 22 '22 17:10

rtcherry