1
我試圖使用正則表達式來匹配在我的路由配置中不以「/ pt /」或「/ en /」開頭的所有字符串。他們可能會或可能沒有額外的文字。
於是我想出了這一點:
$urlRouterProvider.when('^(?!/(pt|en)/).*', function ($injector, $location) {
const path = $location.path();
$location.path('/pt' + path !== '' ? path : '/').replace();
});
不幸的是這引發錯誤:Invalid parameter name '.' in pattern '^(?!/(pt|en)/).*'
什麼是在這種情況下使用正則表達式的正確方法?
EDIT
我已經基於波希米亞響應改變的表達從'{(?!\/(pt|en)\/).*}'
到'^(?!/(pt|en)/).*'
。但錯誤仍然存在。