Skip to content

Instantly share code, notes, and snippets.

@fxfan
Created January 18, 2018 15:16
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 fxfan/4b1905d181ae311a987d61f5fb9aab51 to your computer and use it in GitHub Desktop.
Save fxfan/4b1905d181ae311a987d61f5fb9aab51 to your computer and use it in GitHub Desktop.
case class Diary(date: String, content: String)
object Diary {
def apply(s: String): Diary = {
val lines = s.lines.toSeq
Diary(lines.head, lines.tail.mkString("\n"))
}
}
val diary = """
- 2018年01月19日 金曜日 22:00
む。
- 2018年01月18日 木曜日 22:00
Scala
しま
した。
- 2018年01月20日 土曜日 22:00
"""
val pattern = """- (\d\d\d\d)年(\d\d)月(\d\d)日 .曜日 (\d\d:\d\d)""".r
val diaries = diary.split(s"(?=${pattern})")
.map(_.trim)
.filter(!_.isEmpty)
.map(Diary(_))
.sortBy(_.date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment