我有一个字符串,它看起来像"label:value“项的逗号列表。
package testParsers
import org.scalatest.{Matchers, FlatSpec}
class testReturnStrParser extends FlatSpec with Matchers{
import parsers.ReturnStringParser
"return string parser" should "find the height in ret string" in {
val teststr = "blahblah:123, height:80.3"
val s = ReturnStringParser.findVal("height", teststr)
s should have length 1
s.head shouldEqual ("80.3")
}
it should "work if it is in the middle" in {
val teststr = "blahblah:123, height:80.3,weight:100.0"
val s = ReturnStringParser.findVal("height", teststr)
s should have length 1
s.head shouldEqual ("80.3")
}
}当标签height位于中间时,我正试图使类正常工作:
package parsers
object ReturnStringParser {
def findVal(fieldName: String, s: String) = {
val rx = s"(?<=$fieldName:)"+"(.*)*[^,\\s]*"
(rx.r)
.findAllIn(s)
.toList
}
}发布于 2015-11-06 17:29:13
https://stackoverflow.com/questions/33571746
复制相似问题