【发布时间】:2015-12-24 07:15:58
【问题描述】:
我的代码中有这个正则表达式:
get.HandleFunc("/my/api/user/{userID:^([1-9][0-9]*)$}", app.Handle("user"))
但是当我运行测试时,只返回 404。我也试过这个:
get.HandleFunc("/my/api/user/{userID:\\A([1-9][0-9]*)\\z}", app.Handle("user"))
它与我的旧(但不正确)正则表达式完美配合:
get.HandleFunc("/my/api/user/{userID:[0-9]{1,}}", app.Handle("user"))
我想知道我的新正则表达式有什么问题。我尝试在一些网站上测试它,并在 Go 中使用 regexp 包,它总是有效。据我所知,gorilla/mux 使用 Go 的 regexp 包。有什么想法吗?
我想要的是检测除零以外的正整数。
【问题讨论】: