LoginSignup
5
5

More than 5 years have passed since last update.

scalaで正規表現を使って文字列を抽出する

Posted at

①Regexで正規表現のルールを定義する
②findFirstMatchIn()メソッドで一致する文字列を抽出する

sample.scala
var dateStr = "2013年12月31日"
var monthR : Regex = """[0-9]*月""".r;
var monthRM : Regex.Match = monthR.findFirstMatchIn(dateStr).get

//12月と出力される
println(monthRM.toString)

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5