bidi
bidi copied to clipboard
Capture group confusion
Why does this not work?
(bidi/match-route ["/" {[[#"-?[0-9]+(\.[0-9]+)?" :lat]
"%7C"
[#"-?[0-9]+(\.[0-9]+)?" :lng]
"%7C"
[#"[0-9]+(\.[0-9]+)?" :radius]] {"/b" :geo}}]
"/38.0%7C-78.5%7C10.0/b")
=> {:route-params {:lat "38.0", :lng "%7C", :radius ".5"}, :handler :geo}
If I remove the capture groups (and consequently change the regex to disallow valid integers) then it will "work":
(bidi/match-route ["/" {[[#"-?[0-9]+\.[0-9]+" :lat]
"%7C"
[#"-?[0-9]+\.[0-9]+" :lng]
"%7C"
[#"[0-9]+\.[0-9]+" :radius]] {"/b" :geo}}]
"/38.0%7C-78.5%7C10.0/b")
=> {:route-params {:lat "38.0", :lng "-78.5", :radius "10.0"}, :handler :geo}