Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created January 8, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shigemk2/670507f115757438fe3c to your computer and use it in GitHub Desktop.
Save shigemk2/670507f115757438fe3c to your computer and use it in GitHub Desktop.
val numPattern = "[0-9]+".r
val address = "123 Main Street Suite 101"
// 1つだけマッチ
val match1 = numPattern.findFirstIn(address)
println(match1) // Some(123)
// 複数マッチ
val matches = numPattern.findAllIn(address)
matches.foreach(println)
// 123
// 101
val matches2 = numPattern.findAllIn(address).toArray
println(matches2(0)) // 123
val curePattern = "cure".r
val nomatch = curePattern.findFirstIn(address).getOrElse("no match")
println(nomatch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment