请帮助使用简单的Scala方法:
到目前为止,我试过了:
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)
谢谢!
答案 0 :(得分:2)
你去吧
<强> 1。一个拉丁字母
scala> ("[A-Za-z]".r findFirstIn "Munich").isDefined
res22: Boolean = true
<强> 2。所有拉丁字母
scala> "Munich".toList.forall(c => ( c >= 'A' && c<= 'Z') || (c >= 'a' && c <= 'z') )
res27: Boolean = true
第3。至少一个西里尔字母:
("\\p{IsCyrillic}".r findFirstIn "Москва").isDefined
res5: Boolean = true
<强> 4。所有人都是西里尔人:
val moscow = "Москва"
"\\p{IsCyrillic}*".r.findFirstIn(moscow).map(_.size) == Some(moscow.size)
res21: Boolean = true