scalasprayspray-dsl

How do I write a path matcher that matches any part of the remaining path with a regex?


I'd like to write a path matcher that matches any of the remaining parts of the path with a regex, so for example,

path("myregex".r) 

would match if i have remaining paths in the form:

/myregex
/foo/myregex
/foo/myregex/bar
/myregex/bar

I looked at the code for the regex matcher, it seems like it only looks at the first segment, I could setup multiple routes or write a custom matcher, but was wondering if there is already a better solution for it?

Thanks,


Solution

  • How about this?

      path(Segments){segments=>
        validate(segments.exists(_.matches("myregex")), "unmatched path"){          
          complete(s"matched: $segments")
        }
      }