Skip to content

Conformance Examples 0.1.0 — Transforms: transform-replace

replace-two-string-literals

Replace all occurrences of a substring via {{ phrase | replace: "world" "Mark" }}.

Template

{{ phrase | replace: "world" "Mark" }}

Context

{
    "phrase": "hello world, big world"
}

Output

hello Mark, big Mark

replace-target-absent

Replace when target substring is not present acts as a no-op.

Template

{{ phrase | replace: "xyz" "abc" }}

Context

{
    "phrase": "hello world"
}

Output

hello world

replace-empty-string-target

Replacing empty string inserts replacement before each character and at the end. "ab".replace("", "x") = "xaxbx".

Template

{{ phrase | replace: "" "x" }}

Context

{
    "phrase": "ab"
}

Output

xaxbx

replace-chained-after-upcase

Chaining replace after upcase: {{ phrase | upcase | replace: "WORLD" "Mark" }}.

Template

{{ phrase | upcase | replace: "WORLD" "Mark" }}

Context

{
    "phrase": "hello world"
}

Output

HELLO Mark

Source fixture: transforms/transform-replace.json