java - Split regex in Scala keeping delimiter -
i'm trying split string using regex rules:
- the string should split 2 the first part containing @ least 2 characters
- the second part made of characters starting first number (after second character)
e.g. ab1234 = ab , 1234 , c56789 = c5 , 6789 , zyx3939y = zyx , 3939y
i have regex working, loses character splitting on:
val t = request.number.split("(?<=.{2})[0-9]{1}", 2)
println(t(0), t(1))
gives:
(ab,234) (c5,789) (ezy,9393y)
what correct regex , there easier way of doing this?
you better off using span
, splitat
methods on string
.
val (twofirst, rest) = request.number.splitat(2) val (nonumber, tail) = rest.span(!_.isdigit) (twofirst + nonumber, tail)
the first val
splits input after second character. second val
splits input finds digit.
Comments
Post a Comment