Implement "replacement" variable that simply replaces the match
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user