Common - Add FUNC(escapeRegex) (#9355)

* add function

* add source
This commit is contained in:
Grim
2023-08-30 19:31:10 -04:00
committed by GitHub
parent c88695fb82
commit 8b3b265d87
2 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,20 @@
#include "script_component.hpp"
/*
* Author: LinkIsGrim
* Escapes special characters used in regex from a string
*
* Arguments:
* 0: String <STRING>
*
* Return Value:
* Safe string <STRING>
*
* Example:
* "\Q.*?AK-15.*?\E" call ace_common_fnc_escapeRegex
*
* Public: Yes
*/
params [["_string", "", [""]]];
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
_string regexReplace ["[.?*+^$[\]\\(){}|-]/gio", "\\$&"]