Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex nim re,正则表达式模块未填充匹配组_Regex_Nim Lang - Fatal编程技术网

Regex nim re,正则表达式模块未填充匹配组

Regex nim re,正则表达式模块未填充匹配组,regex,nim-lang,Regex,Nim Lang,我想使用nim库的regex模块: import re var s="""<webSettings> <add key="MyLaborPassword" value="shadowed" /> <add key="MyLaborUserID" value="shadowed" /> <add key="MyLaborUrl" value="shadowed" /> <add key="DebugSoapLoggingEnabled" va

我想使用nim库的regex模块:

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
@["ass"]
我错过了什么?

该模块已被弃用,在我的经验中有点问题。您可以使用新的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]
导入nre,选项
var s=”“”
"""
echo s.find(re“”“mylabort(ass)word“”).get.captures[0]

它打印
ass

我以前也尝试过nre,但我错过了
选项
。。。我还必须用敏捷安装
选项
。在编译之前,我必须清除Nim缓存。您可能使用的是旧版本的Nim。当前的Nim 0.12.0附带了选项模块。Nimcache clearing是一个bug,我希望现在可以修复。
re.find
填充序列(或数组),但不会添加到序列中;如果它是一个空序列,它将保持为空。改用
var matches=newSeq[string](1)
(即一个1元素序列)或使其成为
array[1,string]
。Reimer Behrends,这成功了!但在我看来,这有点奇怪。Davidos Krausos,这是因为
find()
使用
openarray[string]
参数来适应seq和数组,但是
openarray
参数的大小是不可调整的。
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]