Created
January 8, 2015 14:15
-
-
Save shigemk2/670507f115757438fe3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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