以下使用的regex
值不匹配charIntIntIntIntIntInt
::
val regex = "([a-zA-Z]\\d\\d\\d\\d\\d\\d)"
//> regex : String = ([a-zA-Z]\d\d\d\d\d\d)
val f = List("b111111").filter(fi => fi startsWith regex)
//> f : List[String] = List()
f
是一个空列表,它应该包含 b111111
当我在https://www.regex101.com/上使用此正则表达式时,它与字符串正确匹配。
我的筛选方式有问题吗?
如何使用Scala语言正则表达式功能,例如:
val regex = """^([a-zA-Z]\d{6})""".r // enables you to drop escaping \'s
val f = List("b111111").filter { s => regex.findFirstIn(s).isDefined }
有关更多详细信息,请参见http://www.scala-lang.org/api/current/index.html#scala.util.matching.Regex
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句