Skip to content

Instantly share code, notes, and snippets.

@momota10
Last active February 10, 2016 04:34
Show Gist options
  • Save momota10/c2ce1d8bfaf277946473 to your computer and use it in GitHub Desktop.
Save momota10/c2ce1d8bfaf277946473 to your computer and use it in GitHub Desktop.
//split
val url = "https://play.google.com/store/apps/details?id=com.expedia.bookings&hl=ja" //sample_url
val replacedUrl = url.replace("https://", "")
val splitUrl =replacedUrl.split("/")
println(replacedUrl) //play.google.com/store/apps/details?id=com.expedia.bookings&hl=ja
println(splitUrl(0)) //play.google.com
//pattern match
splitUrl(0) match {
case "itunes.apple.com" =>
val iosParse = iosPattern.findFirstMatchIn(url).get
val id = iosParse.group(1)
//your code
case "play.google.com" =>
val androidParse = androidPattern.findFirstMatchIn(url).get
val id = androidParse.group(1)
//your code
case _ => Future.successful(None)
}
//sample
//iOS
val line = "https://itunes.apple.com/ja/app/expedia-hotels-flights-cars/id427916203?mt=8"
val pattern = """.*id([0-9]+)""".r
val m = pattern.findFirstMatchIn(line).get;
println(m.group(1)) //427916203
//android
val line = "https://play.google.com/store/apps/details?id=com.expedia.bookings&hl=ja"
val pattern = """.*id=([a-z]+.[a-z]+.[a-z]+)""".r
val m = pattern.findFirstMatchIn(line).get;
println(m.group(1)) //com.expedia.bookings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment