I am learning Scala and spark and want to get the numbers out of string. And for that i am using the regular expression. And came to know about the weird signature of using regular patterns in Scala.
Here is my code:
val myString: String = "there would be some number here 34."
val pattern = """.* ([\d]+).*""".r
val pattern(numberString) = myString
val num = numberString.toInt
println(answer)
The code is working fine, but seems a bit weird and less readable.
Is there any other way to do this in Scala? Or any other syntax which i can use?
val pattern(numberString) = myString. Could anyone explain that?