Nim: can't run code which uses regular expressions

Problem description:

import re

var regexs: seq[Regex] = @[] # stores all regex

block:
  echo "hello world!"

  regexs.add(re"\d+(\.\d+)?") # number, either a real or integer

try in console

 nim compile --run main.nim
Hint: used config file '/nix/store/ap7nr6hb3q9zhphcy2s2bmxvvvg1yzcq-nim-unwrapped-1.4.8/nim/config/nim.cfg' [Conf]
Hint: used config file '/nix/store/ap7nr6hb3q9zhphcy2s2bmxvvvg1yzcq-nim-unwrapped-1.4.8/nim/config/config.nims' [Conf]
..............CC: stdlib_system.nim
CC: stdlib_pcre.nim
CC: stdlib_strutils.nim
CC: stdlib_re.nim
CC: main.nim

Hint:  [Link]
Hint: 35029 lines; 8.634s; 48.828MiB peakmem; Debug build; proj: /home/runner/23carbonLexer/main.nim; out: /home/runner/23carbonLexer/main [SuccessX]
Hint: /home/runner/23carbonLexer/main  [Exec]
could not load: libpcre.so(.3|.1|)
(compile with -d:nimDebugDlOpen for more information)
Error: execution of an external program failed: '/home/runner/23carbonLexer/main '
exit status 1


Expected behavior:

runs normally

Please format your code by triple backticks.

import re

var regexs: seq[Regex] = @ # stores all regex

block:
echo “hello world!”

regexs.add(re"\d+(.\d+)?") # number, either a real or integer

Add it via Nix: in Shell:

sed -i 's/];/  pkgs.pcre2\
  &/' replit.nix
1 Like