I'm trying to match a given string with nre
:
from nre import findIter, re
const sourceString = """
39
00:04:01,116 --> 00:04:01,783
Attrape.
"""
let srtRex = re"\d+\R\d+:\d+:\d+,\d+ --> \d+:\d+:\d+,\d+\R(\w+)"
for m in findIter(sourceString, srtRex, 0):
echo(m.captures[0])
This doesn't compile though, it fails with Error: undeclared field: 'captures' for type nre.RegexMatch [declared in /usr/local/Cellar/nim/1.2.6/nim/lib/impure/nre.nim(149, 3)]
.
This is weird, because if I do echo(m)
, I get the raw strings, so the match itself worked fine. It's only this field I can't access. And that is weird, because in this issue the (working) example code is pretty much the same.
Importing whole modules is idiomatic in Nim, and leads to ambiguities rarely, thanks to a strong type system. see https://narimiran.github.io/2019/07/01/nim-import.html for a great rundown on why Nim doesn't share Python's import issues.
However, here's how to do what you want to do, even if it's not idiomatic Nim:
You're using more than just
re
andfindIter
, you also use the proccaptures
, and the[]
proc, so your import line needs to be:or, for complete namespace separation, but quite ugly, you can: