匹配案例的行为与Regex.findAll不同

时间:2016-11-19 09:47:37

标签: regex scala debugging

我有一个小帮手方法,必须规范化一些货币价值。因此,我写了一些正则表达式,它们应该检测表示它们的不同方式。奇怪的是,如果与Regex.findAllIn(..)一起使用,它们只会触发,但如果在匹配案例语句中使用则不会触发。

<div class="container">
  <div class="row">
    <!---MAIN COLUMN------>
    <div class="col-xs-12 col-md-6 col-sm-8 col-lg-6 col-centered">
      <h2>
        How to keep the text inside the div?
      </h2>

      <div class="mytext">
        fdsnkfhskghkgskghsdkghdskghdsklhgkdlsghds
        khgkdshgdksghdsklghdskg hkdslhgkdshgkdshgkdshgkd
        shgksdlhgksdhgkdslhgkdshgkdshgkdshgksd hgkldshgkd
        shgkldshgkhdsgkhdskghdskhgkdlshgkdshgkldsh
        gkdshgklhds kghdskghdskl
        <small>
        </small>

      </div>

    </div>
  </div>
</div>

调试器输出命中Regex.findAllIn(..): debugger screen shot 1

调试器输出未达到Dot(值)的匹配大小写: debugger screen shot 2

同样有趣的可能是在调试器中跟随错误消息: Debugger error message

使用scala版本2.11.8。

我很困惑,肯定忽略了一些明显的东西。感谢提示。

1 个答案:

答案 0 :(得分:3)

而不是做例如。

case Dot(values) => new BigDecimal(s"${values(0)}.${values(1)}")

重写Regex提取器的用法,如下所示:

case Dot(a, b) => new BigDecimal(s"$a.$b")

每个提取器中的参数数量必须与正则表达式所包含的组数量相匹配(此处:2)。每个参数只是一个表示单个组内容的字符串。

相关问题