匹配一个或在AngularJS UI路由器另一个词 [英] Matching one or another word in AngularJS ui-router

查看:149
本文介绍了匹配一个或在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?

推荐答案

按照<一个href=\"https://github.com/angular-ui/ui-router/wiki/URL-Routing#wiki-regex-parameters\">documentation你不应该使用您正则表达式模式捕获括号。

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

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

这篇关于匹配一个或在AngularJS UI路由器另一个词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆