Q:

play-framework 2 how to escape colon in routes

in my play2 routes file, I am trying to use a colon as a literal:
GET     /:search                       controllers.SearchController.index()

but play complains, that a parameter is missing. How do I escape the colon (I tried backslashing it)?
thanks

A:

You must introduce a dummy regex parameter, as such:
GET     /$colon<\:>search           controllers.SearchController.index(colon)

You must then also redefine your controller method:
public static Result index(String colon) {
 ....

The parser is built in such a way that path expressions cannot be escaped, save for this method.

