regex - Scala extracting only certain characters -


i taking in line line in scala string, , want able remove characters don't belong arbitrary collection of letters s.

would val pattern = s.r? , how parse line remove characters not in s?

you can use filternot remove character in collection.

scala> val vowels = set("a","e","i","o","u") vowels: scala.collection.immutable.set[string] = set(e, u, a, i, o)  scala> val line = """i taking in line line in scala string, , want able remove characters don't belong arbitrary collection of letters s.""" line: string = taking in line line in scala string, , want able remove characters don't belong arbitrary collection of letters s.  scala> line.filternot(x => vowels.contains(x.tostring)) res4: string = m tkng n ln ln n scl s  strng, nd wnt t b bl t rmv ll chrctrs tht dn't blng t sm rbtrry cllctn f lttrs s. 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -