0
マッチング正規表現パターンは、私は次の入力文字列を持っているスカラ:
"/horses/[email protected]"
"/Goats/[email protected]"
"/CATS/[email protected]"
私は、次の
StandardTokenParsers
を試みた出力"horses", "c132", "[email protected]"
"Goats", "b-01", "[email protected]"
"CATS", "001", "[email protected]"
として以下を取得したいのですが
import scala.util.parsing.combinator.syntactical._
val p = new StandardTokenParsers {
lexical.reserved ++= List("/", "?", "XXX=")
def p = "/" ~ opt(ident) ~ "/" ~ opt(ident) ~ "?" ~ "XXX=" ~ opt(ident)
}
p: scala.util.parsing.combinator.syntactical.StandardTokenParsers{def p: this.Parser[this.~[this.~[this.~[String,Option[String]],String],Option[String]]]} = [email protected]
scala> p.p(new p.lexical.Scanner("/horses/[email protected]"))
warning: there was one feature warning; re-run with -feature for details
res3: p.ParseResult[p.~[p.~[p.~[String,Option[String]],String],Option[String]]] =
[1.1] failure: ``/'' expected but ErrorToken(illegal character) found
/horses/[email protected]
^
正規表現
import scala.util.matching.regex
val p1 = "(/)(.*)(/)(.*)(?)(XXX)(=)(.*)".r
p1: scala.util.matching.Regex = (/)(.*)(/)(.*)(?)(XXX)(=)(.*)
scala> val p1(_,animal,_,id,_,_,_,company) = "/horses/[email protected]"
scala.MatchError: /horses/[email protected] (of class java.lang.String)
... 32 elided
誰かが助けてくださいことはできますか?ありがとう!