diff --git a/README.asciidoc b/README.asciidoc index 841943fae7..d51cc017b6 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -74,6 +74,9 @@ Replaces each match of Regex in the string with `sub`. If `sub` is a `proc (RegexMatch): string`, then it is executed with each match and the return value is the replacement value. +If `sub` is a `proc (string): string`, then it is executed with the full text +of the match and and the return value is the replacement value. + If `sub` is a string, the syntax is as follows: - `$$` - literal `$` diff --git a/src/nre.nim b/src/nre.nim index e56194fd6f..c0c286b0d0 100644 --- a/src/nre.nim +++ b/src/nre.nim @@ -445,6 +445,10 @@ proc replace*(str: string, pattern: Regex, subproc: proc (match: RegexMatch): string): string = replaceImpl(str, pattern, subproc(match)) +proc replace*(str: string, pattern: Regex, + subproc: proc (match: string): string): string = + replaceImpl(str, pattern, subproc(match.match)) + proc replace*(str: string, pattern: Regex, sub: string): string = # - 1 because the string numbers are 0-indexed replaceImpl(str, pattern,