regex - nim re,正则表达式模块没有填充匹配组

标签 regex nim-lang

我想使用 nim 库的正则表达式模块:

import re

var s="""<webSettings>
<add key="MyLaborPassword" value="shadowed" />
<add key="MyLaborUserID" value="shadowed" />
<add key="MyLaborUrl" value="shadowed" />
<add key="DebugSoapLoggingEnabled" value="false" />
  </webSettings>
 """


var matches : seq[string] = @[]

echo s.find(re"""MyLaborP(ass)word""",matches)
echo matches

给我

25
@[]

但我除了:

25
@["ass"]

我错过了什么?

最佳答案

re模块已弃用,根据我的经验,它有点问题。您可以使用新的 nre 模块:

import nre, options

var s="""<webSettings>
<add key="MyLaborPassword" value="shadowed" />
<add key="MyLaborUserID" value="shadowed" />
<add key="MyLaborUrl" value="shadowed" />
<add key="DebugSoapLoggingEnabled" value="false" />
  </webSettings>
 """


echo s.find(re"""MyLaborP(ass)word""").get.captures[0]

打印 ass

关于regex - nim re,正则表达式模块没有填充匹配组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33872103/

相关文章:

c# - 正则表达式匹配所有字母数字和某些特殊字符?

regex - Oracle查询查找不包含字符的字符串

正则表达式 6 位数字彼此相邻

command-line-interface - 如何使用 `argparse` 为 nim 提供可变数量的参数

nim-lang - Nim 代码解析器

compiler-errors - 错误: expression 'readLine(stdin)' is of type 'TaintedString' and has to be discarded

python - 解析 dbus 监视器输出消息

Python:引发 argparse.ArgumentError 后,argparse 引发一般错误

c# - 与 nim 互操作返回包含 string/char* 成员的结构数组

c - 假设没有 “lend”,将 “concurrent access”内存块安全地锁定到C中的另一个线程