原创文章,转载请注明出处!

原文地址: http://www.ptbird.cn/2016/07/19/scala-chuji-demo-18/

There I am,in the world more exciting!

by postbird

www.ptbird.cn



package com.ptbird.scala /** * Created by postbird on 2016/5/25. * * 正则表达式 */ object RexpTest { def main(args: Array[String]): Unit = { val regex ="""([0-9]+)([a-z]+)""".r val numPattern = "[0-9]+".r val numberPattern ="""\s+[0-9]+\s+""".r for (matchString <- numPattern.findAllIn("99235 scala,22298 spark")) { //println(matchString) // 99235 // 22298 } // println(numberPattern.findFirstIn("99ss java , 2222 hadoop")) //Some( 2222 ) val numitemPattern = """([0-9]+)([a-z]+)""".r val numitemPattern(num , item) = "99 hadoop" val line = "93459 spark" line match { case numitemPattern(num, blog) => println(num + "\t" + blog) case _ => println("noen.....") } } }