Let's say I have this code:
val string = "one493two483three"
val pattern = """two(d+)three""".r
pattern.findAllIn(string).foreach(println)
I expected findAllIn
to only return 483
, but instead, it returned two483three
. I know I could use unapply
to extract only that part, but I'd have to have a pattern for the entire string, something like:
val pattern = """one.*two(d+)three""".r
val pattern(aMatch) = string
println(aMatch) // prints 483
Is there another way of achieving this, without using the classes from java.util
directly, and without using unapply?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…