Skip to content

Feature Request: Add regex_replace Filter for Template Variables #5382

@Tealk

Description

@Tealk

Is your feature request related to a problem? Please describe.

Currently, when working with template variables in Element Mas, there is no way to apply regular expression replacements. This forces users to chain multiple replace filters together to achieve complex string transformations, resulting in very long and hard-to-maintain template chains.

For example, removing all special characters from a username requires an extremely long filter chain:

{{ user.preferred_username | replace("ä", "ae") | replace("ö", "oe") | replace("ü", "ue") | replace("Ä", "Ae") | replace("Ö", "Oe") | replace("Ü", "Ue") | replace("ß", "ss") | replace("_", "-") | replace(".", "") | replace("@", "") | replace(" ", "") | replace("$", "") | replace("%", "") | replace("&", "") | replace("#", "") | replace("!", "") | replace("+", "") | replace("=", "") | replace("*", "") | replace("(", "") | replace(")", "") | lower }}

Attempting to use a regex_replace filter currently results in: unknown filter: filter regex_replace is unknown

Describe the solution you'd like

Implement a regex_replace filter that accepts a regular expression pattern and a replacement string. This would allow complex string transformations in a single, readable filter call:

{{ user.preferred_username | regex_replace("[^A-Za-z0-9-]", "") | lower }}

Describe alternatives you've considered

  • Using multiple chained replace filters (current workaround, but becomes unwieldy with many patterns)
  • Preprocessing usernames before passing them to templates (adds complexity to the application logic)
  • Creating custom template functions outside the templating system (requires additional code maintenance)

A native regex_replace filter would be the most maintainable and user-friendly solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions