Hello,
Could you please help to understand highlighted below code.
def extractIP(line:String): String = {
*val pattern = "^([0-9\.+). $".r
val pattern = (ip:String) = line
return (ip.toString)
}
thanks.
Hello,
Could you please help to understand highlighted below code.
def extractIP(line:String): String = {
*val pattern = "^([0-9\.+). $".r
val pattern = (ip:String) = line
return (ip.toString)
}
thanks.
It seems you are trying to find pattern with help of creating Regex object .
We create a Regex object for the pattern we would like to search for in this
case, a sequence of one or more numeric characters:
scala> val numPattern = “[0-9]+”.r
numPattern: scala.util.matching.Regex = [0-9]+
Next, create a sample String you can search:
scala> val address = “123 Main Street Suite 101”
address: java.lang.String = 123 Main Street Suite 101
The findFirstIn method finds the first match:
scala> val match1 = numPattern.findFirstIn(address)
match1: Option[String] = Some(123)
I recommend you go to scala string tutorial and elaborate more.
val pattern = “^([0-9\.]+) .*$”.r
val pattern(ip:String) = line
in above code lines, is pattern a variable or function? As name is same but in second line it consists argument.