Skip to main 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.

Replace Characters

replace

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.

replace_first

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" ?}`
Returns: My favorite colour is blue, her favorite color is red.

Remove Characters

remove

Removes every occurrence of the specified substring from a string

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

remove_first

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

strip

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

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

rstrip

Removes all whitespace characters from the right side of a string

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

lstrip

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

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

strip_newlines

Removes all newline characters from the string

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