【问题标题】:Regular Expressions in Erlang. Adding additional match in a result listErlang 中的正则表达式。在结果列表中添加其他匹配
【发布时间】:2021-09-24 15:31:27
【问题描述】:

我正在学习如何在 Erlang 中使用正则表达式获取字符串。 请向我解释为什么当我对值是从 0 到 255 的序列的元素列表执行正则表达式时,大于 127 的值会落入结果列表中?

Expected = true,
ValidCharacterList = lists:seq(0, 255),

RegularExpression = "[[:ascii:]]",
{ok, MP} = re:compile(RegularExpression),
{match, _} = re:run(ValidCharacterList, MP),
Result = true,
?assertEqual(Expected, Result).

结果是该序列的所有元素(从 0 到 255)。

Full code example.

More code examples.

【问题讨论】:

    标签: regex erlang


    【解决方案1】:

    POSIX 的:ascii: 定义为[\x00-\x7F]。但是请注意,Erlang states

    还有另一个字符类 ascii,它错误地匹配 Latin-1 字符,而不是 POSIX 指定的 0-127 范围。如果不改变其他类的行为就无法解决此问题,因此我们建议将范围与 [\0-\x7f] 匹配。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多