Reputation: 289
How to remove numbers form a text in Scala ?
for example i have this text:
canon 40 22mm lens lock strength plenty orientation 321 .
after removing :
canon lens lock strength plenty orientation .
Upvotes: 5
Views: 5481
Reputation: 48745
Since it is apparent, you want to remove all words that contain a number, because in your example mm
is also gone, because it is prefixed by a number.
val s = "That's 22m, which is gr8."
s.split(" ").filterNot(_.exists(_.isDigit)).mkString(" ")
res8: String = That's which is
Upvotes: 1
Reputation:
Please, try filter
or filterNot
val text = "canon 40 22mm lens lock strength plenty orientation 321 ."
val without_digits = text.filter(!_.isDigit)
or
val text = "canon 40 22mm lens lock strength plenty orientation 321 ."
val without_digits = text.filterNot(_.isDigit)
Upvotes: 8
Reputation: 67968
\\d+\\S*\\s+
Try this.Replace by empty string
.See demo.
https://regex101.com/r/tS1hW2/1
Upvotes: 2