Skip to content

Replace and Remove Filters for Scriptlets

Scriptlets allow you to easily replace or remove text from a string with filters. You may replace the first occurrence of a string with another string, or remove all occurrences of a string from the input text.

Replaces every occurrence of the first argument in a string with the second argument

{? "I've recieved the gift. Thank you 🎉" | replace: "recieve", "receive" ?}`
Output
I've received the gift. Thank you 🎉
{? "My favorite color is blue, her favorite color is red." | replace: "color", "colour" ?}`
Output
My favorite colour is blue, her favorite colour is red.

Replaces only the first occurrence of the first argument in a string with the second argument

{? "My favorite color is blue, her favorite color is red." | replace_first: "color", "colour" ?}`
Output
My favorite colour is blue, her favorite color is red.

Removes every occurrence of the specified substring from a string

{? "This is dummy xyz text xyz" | remove: "xyz" ?}
Output
This is dummy text

Removes only the first occurrence of the specified substring from a string

{? "This is dummy xyz text xyz" | remove_first: "xyz" ?}
Output
This is dummy text xyz

Removes all whitespace characters (newlines, tabs, spaces) from the left and right sides of a string

{? " World! " | prepend: " Hello " | strip ?}
Output
Hello World!

Removes all whitespace characters from the right side of a string

{? "Hello! \t\n " | downcase | rstrip ?}
Output
hello!

Removes all whitespace characters from the left side of a string”

{? "\t \n Hello!\n" | downcase | lstrip ?}
Output
hello!\n

Removes all newline characters from the string

{? " \n Sentence 1 \nSentence 2! \t\n " | downcase | strip_newlines ?}