martini 库中的路由匹配

老青蛙嘎嘎嘎 2014-03-03 09:58:27
下面这段代码摘自martini库
+func newRoute(method string, pattern string, handlers []Handler) route {
+ route := route{method, nil, handlers}
+ r := regexp.MustCompile(`:[^/#?()\.\\]+`)
+ pattern = r.ReplaceAllStringFunc(pattern, func(m string) string {
+ return fmt.Sprintf(`(?P<%s>[^/#?]+)`, m[1:len(m)])
+
+ })
+ pattern += `\/?`
+ route.regex = regexp.MustCompile(pattern)
+ return route
+}

谁能解释下其中的正则表达式啊?
...全文
163 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

2,348

社区成员

发帖
与我相关
我的任务
社区描述
go语言学习与交流版
社区管理员
  • go语言社区
  • 俺叫西西弗斯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧