scala> //PS:119 scala> //psn > a40 > a50 scala> val myList = Seq( | "Marks in physics=88,", | "Other marks : english=75, science=80" | ) myList: Seq[String] = List(Marks in physics=88,, Other marks : english=75, science=80) scala> scala> //A regex is created using 'r' method scala> val Regex1 = """.*physics=([^,]+),""".r Regex1: scala.util.matching.Regex = .*physics=([^,]+), scala> scala> for(element <- myList) { | val result = element match { | case Regex1(phy) => s"Physics mark =${phy}" | case _ => s"Others : $element" | } | println(result) | } Physics mark =88 Others : Other marks : english=75, science=80
Note : Regex related methods are available in scala.util.matching.Regex
No comments:
Post a Comment