匹配一个或在AngularJS UI路由器另一个词

匹配一个或在AngularJS UI路由器另一个词

问题描述:

使用AngularJS + UI的路由器,我需要一个url与两个单字之一匹配:

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

即。 / oneWord /... / secondWord ...

路由和控制器几乎是一样的,所以我想,以避免重复code。

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

然而,使用我已经习惯了这样的regex,地方不工作定期EX pressions应该工作:

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

URL:/ {类型:(oneWord | secondWord)} /:组,

但是,它抛出一个错误:

However, it throws an error:

在航线不平衡捕获组/ {类型:(oneWord | secondWord)} /:集团

一个正则表达式应该工作,虽然,因为这工作得很好:

A regex should work though, because this works fine:

URL:/ {页:[0-9] {1,8}

我知道?(oneWord | secondWord)是一个有效的正则表达式,所以你有什么我错过

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

按照documentation你不应该使用您正则表达式模式捕获括号。

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

这应该工作: URL:/ {类型:( ?: oneWord | secondWord)} /:集团