Text Replacement (Expression) — Skript

Addon: Skript · Category: Expression · Since: 2.16

Syntax

%strings% where [([the] first instance[s]|all instances) of] %strings% (is|are) replaced with %string% [using regex|with case sensitivity]

Description

Performs a text replacement on a given value, returning the result. Supports regex and case sensitive replacement.

Examples

send "Welcome [player]" where "[player]" is replaced with "%player%" to player
# Function for sanitizing user inputs
# Strips the input of any non-alphanumeric characters using regex
function sanitizeInput(input: string) :: string:
	return {_input} where regex pattern "\W" is replaced with ""
# Function to convert &# hex color codes to <# > (mini message format)
function colorFormat(input: string) :: string:
	return {_input} where all instances of regex pattern "&#([a-fA-F0-9]{6})" are replaced with "<#$1>"
# Very simple chat censor
on chat:
	set message to message where all instances of "idiot", "noob" are replaced with "****"
	set message to message where regex "\b(idiot|noob)\b" is replaced with "****" # Regex version using word boundaries for better results

View source