Skip to content

Instantly share code, notes, and snippets.

@animatedlew
Created November 3, 2016 21:22
Show Gist options
  • Select an option

  • Save animatedlew/6b809d7cbc321e1a04e68babd7d0a3eb to your computer and use it in GitHub Desktop.

Select an option

Save animatedlew/6b809d7cbc321e1a04e68babd7d0a3eb to your computer and use it in GitHub Desktop.
// define your regex groups: one that grabs everything from the end of the line,
// and another group that grabs everything else...
val pathExtractor = """(.*/)(.*)$""".r
// then you can use unapply like this...
val pathExtractor(path, file) = "some/long/path/file.ext"
// or like this (recommended)
"some/long/path/file.ext" match {
case pathExtractor(p, f) => p -> f
case _ => ("NO_PATH", "NO_FILE")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment