summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/impure/re.nim2
-rw-r--r--tests/stdlib/tbug5382.nim11
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/impure/re.nim b/lib/impure/re.nim
index 9d5d2bdd0..e00f91de1 100644
--- a/lib/impure/re.nim
+++ b/lib/impure/re.nim
@@ -290,7 +290,7 @@ proc find*(buf: cstring, pattern: Regex, matches: var openArray[string],
   for i in 1..int(res)-1:
     var a = rawMatches[i * 2]
     var b = rawMatches[i * 2 + 1]
-    if a >= 0'i32: matches[i-1] = bufSubstr(buf, int(a), int(b)-1)
+    if a >= 0'i32: matches[i-1] = bufSubstr(buf, int(a), int(b))
     else: matches[i-1] = nil
   return rawMatches[0]
 
diff --git a/tests/stdlib/tbug5382.nim b/tests/stdlib/tbug5382.nim
new file mode 100644
index 000000000..c86656d32
--- /dev/null
+++ b/tests/stdlib/tbug5382.nim
@@ -0,0 +1,11 @@
+discard """
+  output: '''
+02
+'''
+"""
+import re
+
+let regexp = re"^\/([0-9]{2})\.html$"
+var matches: array[1, string]
+discard "/02.html".find(regexp, matches)
+echo matches[0]