Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

Locked History Actions

scala/Regex

正規表現

参考

正規表現使用上の注意事項

正規表現をmatch式に使う場合は必ず_*引数をつける(少なくとも最後の引数として)

object RegEx {

  val PATTERN = """^[A-Z]+$""".r
  val pattern = """^[A-Z]+$""".r
  
  def main(args: Array[String]) {
    println("ABC" match { // 1
      case PATTERN => "matched"
      case _ => "unmatched"
    })
    println("ABC" match { // 2
      case PATTERN(_*) => "matched"
      case _ => "unmatched"
    })
    println("ABC" match { // 3
      case pattern => "matched"
      //case _ => "unmatched"
    })    
    println("ABC" match { // 4
      case pattern(_*) => "matched"
      case _ => "unmatched"
    })
  }
}

上記の実行結果は

unmatched
matched
matched
matched