Migrate from std/nre -> nitely/regex

std/nre depends on PCRE v1 which is being deprecated by a number of
major distributions (Debian specifically). The core Nim team does not
have a plan currently to migrate it to PCRE v2. nitely/regex is a
Nim-native PCRE-compatible replacement.

AI-Assisted: yes
AI-Tool: codex gpt-5.4 xhigh
This commit is contained in:
Jonathan Bernard
2026-03-19 10:52:31 -05:00
parent 8e972851f3
commit f366c3e1ce
2 changed files with 9 additions and 9 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
# Package
version = "1.0.0"
version = "1.0.1"
author = "Jonathan Bernard"
description = "URL shortener/expander for Probatem at https://pbtm.us"
license = "GPL3"
@@ -11,7 +11,7 @@ bin = @["short_url"]
# Dependencies
requires "nim >= 2.2.4"
requires @["cliutils", "mummy", "namespaced_logging >= 2.1.2", "webby"]
requires @["cliutils", "mummy", "namespaced_logging >= 2.1.2", "regex", "webby"]
task updateVersion, "Update the version of this package.":
exec "update_version interactive src/short_url.nim"
+7 -7
View File
@@ -1,5 +1,5 @@
import std/[json, nre, posix, sequtils, strutils]
import cliutils, docopt, mummy, namespaced_logging
import std/[json, posix, sequtils, strutils]
import cliutils, docopt, mummy, namespaced_logging, regex
import webby/httpheaders
const USAGE = """
@@ -14,7 +14,7 @@ Options:
--trace Enable trace-level logging (takes precedence over --debug).
"""
const VERSION = "1.0.0"
const VERSION = "1.0.1"
const CT_TXT = "text/plain"
type
@@ -24,7 +24,7 @@ type
cfg: CombinedConfig
Context = object
mappings: seq[tuple[src:string, regex: Regex, tmpl: string]]
mappings: seq[tuple[src:string, regex: Regex2, tmpl: string]]
logger: Logger
proc loadConfig(args: Table[string, Value]): ShortUrlsConfig =
@@ -40,8 +40,8 @@ proc loadConfig(args: Table[string, Value]): ShortUrlsConfig =
result.mappings.add((k, v.getStr))
proc initMappings(m: seq[tuple[src, dst: string]]):
seq[tuple[src: string, regex: Regex, tmpl: string]] =
result = m.mapIt((it.src, re(it.src), it.dst))
seq[tuple[src: string, regex: Regex2, tmpl: string]] =
result = m.mapIt((it.src, re2(it.src), it.dst))
proc makeHandler(mappings: seq[tuple[src,dst: string]], logSvc: LogService): RequestHandler =
let ctx = Context(
@@ -56,7 +56,7 @@ proc makeHandler(mappings: seq[tuple[src,dst: string]], logSvc: LogService): Req
return
for (src, regex, tmpl) in ctx.mappings:
if match(req.uri, regex).isSome:
if req.uri.startsWith(regex):
ctx.logger.debug(%*{
"msg": "found match",
"matching_pattern": %src,