diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index ae1523039..99810d98b 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -2131,6 +2131,86 @@ export function initDefaultSlashCommands() { `, })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'test', + callback: (({ pattern }, text) => { + if (pattern === '') { + throw new Error('Argument of \'pattern=\' cannot be empty'); + } + let re = regexFromString(pattern.toString()); + return JSON.stringify(re.test(text.toString())); + }), + returns: 'true | false', + namedArgumentList: [ + new SlashCommandNamedArgument( + 'pattern', 'pattern to find', [ARGUMENT_TYPE.STRING], true, false, + ), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'text to test', [ARGUMENT_TYPE.STRING], true, false, + ), + ], + helpString: ` +
true
if the match is found, false
otherwise.
+ /let x Blue house and green car ||+
/test pattern="green" {{var::x}} | /echo |/# true ||+
/test pattern="blue" {{var::x}} | /echo |/# false ||+
/test pattern="/blue/i" {{var::x}} | /echo |/# true ||+
/g
),
+ multiple nested arrays are returned for each match. If the regex is global, returns []
if no matches are found,
+ otherwise it returns null.
+ /let x color_green green lamp color_blue ||+
/match pattern="green" {{var::x}} | /echo |/# [ "green" ] ||+
/match pattern="color_(\\w+)" {{var::x}} | /echo |/# [ "color_green", "green" ] ||+
/match pattern="/color_(\\w+)/g" {{var::x}} | /echo |/# [ [ "color_green", "green" ], [ "color_blue", "blue" ] ] ||+
/match pattern="orange" {{var::x}} | /echo |/# null ||+
/match pattern="/orange/g" {{var::x}} | /echo |/# [] ||+