mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-02 03:02:31 +00:00
Add replace(proc(string): string)
This commit is contained in:
@@ -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 `$`
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user