Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nim re, regex modul is not filling match group

Tags:

regex

nim-lang

I want to use the regex module of the nim library:

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

Gives me

25
@[]

but i except:

25
@["ass"]

what have i missed?

like image 806
enthus1ast Avatar asked Dec 21 '25 13:12

enthus1ast


1 Answers

The re module is deprecated and has been a bit buggy in my experience. You can use the new nre module:

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]

Which prints ass.

like image 106
def- Avatar answered Dec 24 '25 04:12

def-



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!