You can get rid of a lot of cracks just by using the extractor in the for feeling:
val Token = """^\s*ideas_token\s*=\s*(\w+)\s*$""".r val tokenFromHeader = for { Token(t) <- request.headers.get("authorization") } yield t tokenFromHeader orElse request.queryString.get("ideas_token")
But the following is even more concise and slightly clear, in my opinion:
val Token = """^\s*ideas_token\s*=\s*(\w+)\s*$""".r request.headers.get("authorization") collect { case Token(t) => t } orElse request.queryString.get("ideas_token")
Both are essentially equivalent, although in both cases you simply pull the value (if it exists) from Option and see if it matches the regular expression.
source share