Scala正则表达式提取器

示例

具有分组部分的正则表达式可以用作提取器:

scala> val address = """(.+):(\d+)""".r

address: scala.util.matching.Regex = (.+):(\d+)

scala> val address(host, port) = "some.domain.org:8080"

host: String = some.domain.org

port: String = 8080

请注意,如果不匹配,MatchError则会在运行时抛出a :

scala> val address(host, port) = "something not a host and port"

scala.MatchError: something not a host and port (of class java.lang.String)

           

以上是 Scala正则表达式提取器 的全部内容, 来源链接: utcz.com/z/321286.html

回到顶部