Implement "replacement" variable that simply replaces the match

This commit is contained in:
2025-03-26 12:58:51 +01:00
parent 7e19cf4e2c
commit 7f4392b10e
2 changed files with 29 additions and 23 deletions

View File

@@ -871,7 +871,7 @@ func TestLuaFunctionsOnNamedCaptures(t *testing.T) {
`<user name="(?<name>[^"]+)" role="(?<role>[^"]+)"`,
`-- Capitalize first letters for regular users
if role == "user" then
name = name:gsub("(%w)(%w*)", function(first, rest) return first:upper()..rest end):gsub(" (%w)(%w*)", " %1%2":gsub("%%1", function(x) return x:upper() end))
name = name:gsub("(%w)(%w*)", function(first, rest) return first:upper()..rest end):gsub(" (%w)(%w*)", " %1%2")
else
-- Uppercase for admins
name = string.upper(name)
@@ -910,10 +910,10 @@ func TestNamedCaptureWithMath(t *testing.T) {
p := &RegexProcessor{}
result, mods, matches, err := p.ProcessContent(
content,
`<item price="(?<price>\d+\.\d+)" quantity="(?<qty>\d+)"`,
`<item price="(?<price>\d+\.\d+)" quantity="(?<qty>\d+)"!any$`,
`-- Calculate and add total
replacement = string.format('<item price="%s" quantity="%s" total="%.2f" />',
price, qty, price * qty)`)
price, qty, price * qty)`)
if err != nil {
t.Fatalf("Error processing content: %v", err)