VividCortex / siesta

Composable framework for writing HTTP handlers in Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accept '.' in regexp

Preetam opened this issue · comments

expr = strings.Replace(expr, ">", ">[\\d\\w\\-\\_]+)", -1)

expr = strings.Replace(expr, ">", ">[\\d\\w\\-\\_]+)", -1)

I'm doing something like GET /<host> where host is an IP address. @xaprb, do you think it's a good idea to add periods to the regexp?

Why would periods be a bad idea?

Somewhat related, I'd stick the regex in single quotes so that you don't have to double escape everything. Also, you can simplify that regex bit. This should be equivalent.>[\w-]+because\dis included in\wand you don't have to escape-. If you want the dot, you don't have to escape it within square brackets because it only means "match all" outside of brackets. So this: >[\w-_.]+would match>1-under_score.10but it correctly would not match>@at_is_bad`.

I agree. I borrowed that code and didn't change it because I thought the original author wrote it that way for certain reasons. :)

I think the original author wasn't fluent in regexp :)