Scala: detect cyrillic and latin characters in string? -
please simple scala method allows to:
- detect if string contains @ least 1 latin character
- detect if string characters latin
- detect if string contains @ least 1 cyrillic character
- detect if string characters cyrillic
so far tried:
scala> val pattern = new regex("[a-za-z]") pattern: scala.util.matching.regex = [a-za-z] scala> val s = "john" s: string = john scala> pattern findfirstin s res22: option[string] = some(j)
thanks!
here go
1. 1 latin char
scala> ("[a-za-z]".r findfirstin "munich").isdefined res22: boolean = true
2. latin char
scala> "munich".tolist.forall(c => ( c >= 'a' && c<= 'z') || (c >= 'a' && c <= 'z') ) res27: boolean = true
3. @ least 1 cyrillic char:
("\\p{iscyrillic}".r findfirstin "Москва").isdefined res5: boolean = true
4. chars cyrillic:
val moscow = "Москва" "\\p{iscyrillic}*".r.findfirstin(moscow).map(_.size) == some(moscow.size) res21: boolean = true
Comments
Post a Comment