2

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,

Alex
  • 2,342
  • 1
  • 18
  • 30

1 Answers1

1

How about this?

  path(Segments){segments=>
    validate(segments.exists(_.matches("myregex")), "unmatched path"){          
      complete(s"matched: $segments")
    }
  }
Julio
  • 720
  • 7
  • 16
  • that's it, i think you just opened my eyes to a whole lot of wrong I was previously trying to do :) – Alex Aug 26 '14 at 14:11
  • That would be one solution. However, failing `validate` does not result in the same HTTP error code as directly using a custom PathMatcher. – jrudolph Aug 27 '14 at 08:00