It drives me crazy ... there should be a way to cross out all non-digital characters (or do some other simple filtering) in String.
Example: I want to change the phone number ("+72 (93) 2342-7772" or "+1 310-777-2341") into a simple numeric string (not Int), such as "729323427772", or "13107772341" .
I tried "[\\d]+".r.findAllIn(phoneNumber)that Iteratee returns, and then I would have to recompile them into String somehow ... it seems terribly wasteful.
I also came up with: phoneNumber.filter("0123456789".contains(_)) but that gets tedious for other situations. For example, deleting all punctuation marks ... I'm really for something that works with a regular expression, so it has a wider application than just selecting numbers.
Does anyone have a fantastic one-line Scala for this more direct?
source
share