Skip to content

feat: add String.replaceRegex method#42

Open
wingyplus wants to merge 1 commit into
vito:mainfrom
wingyplus:string-replace-regex
Open

feat: add String.replaceRegex method#42
wingyplus wants to merge 1 commit into
vito:mainfrom
wingyplus:string-replace-regex

Conversation

@wingyplus
Copy link
Copy Markdown

@wingyplus wingyplus commented Apr 16, 2026

Adds replaceRegex(pattern, new, count) to the String stdlib, similar to String.replace but accepts a RE2 regular expression as the search pattern. Supports capture group substitution ($1, $2, ...) and the same count parameter as replace (-1 replaces all, n >= 0 limits replacements). Also adds tests/test_string_replace_regex.dang covering replace-all, count-limited, capture groups, and case-insensitive patterns.

I found this method is useful when we want to replace a complex string with a new one, for example, replace an image in sdk/elixir/runtime/main.go to match with the image defined in the elixir-sdk toolchain.

Adds replaceRegex(pattern, new, count) to the String stdlib, similar to
String.replace but accepts a RE2 regular expression as the search pattern.
Supports capture group substitution ($1, $2, ...) and the same count
parameter as replace (-1 replaces all, n >= 0 limits replacements).
Also adds tests/test_string_replace_regex.dang covering replace-all,
count-limited, capture groups, and case-insensitive patterns.

Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>
@wingyplus wingyplus changed the title gggggsfeat: add String.replaceRegex method feat: add String.replaceRegex method Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant