aboutsummaryrefslogtreecommitdiffstats
path: root/global-functions
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-03-17 08:51:23 +0100
committerGravatar Christian Hesse <mail@eworm.de>2021-03-17 08:51:23 +0100
commit7c4ab95394094d35499429504c6d393df27f08a9 (patch)
tree02715f0847cf917ef812eaff4dd1ffe6a5d58531 /global-functions
parentbaa096fe03440725f8b72912daa3df7c30a6dbc0 (diff)
global-functions: introduce $EscapeForRegEx
Diffstat (limited to 'global-functions')
-rw-r--r--global-functions23
1 files changed, 23 insertions, 0 deletions
diff --git a/global-functions b/global-functions
index 042d89b..7b61f72 100644
--- a/global-functions
+++ b/global-functions
@@ -24,6 +24,7 @@
:global DeviceInfo;
:global DNSIsResolving;
:global DownloadPackage;
+:global EscapeForRegEx;
:global FlushEmailQueue;
:global FlushTelegramQueue;
:global GetMacVendor;
@@ -289,6 +290,28 @@
:return false;
}
+# escape for regular expression
+:set EscapeForRegEx do={
+ :local Input [ :tostr $1 ];
+
+ :if ([ :len $Input ] = 0) do={
+ :return "";
+ }
+
+ :local Return "";
+ :local Chars "^.[]\$()|*+\?{}\\";
+
+ :for I from=0 to=([ :len $Input ] - 1) do={
+ :local Char [ :pick $Input $I ];
+ :if ([ :find $Chars $Char ]) do={
+ :set Char ("\\" . $Char);
+ }
+ :set Return ($Return . $Char);
+ }
+
+ :return $Return;
+}
+
# flush e-mail queue
:set FlushEmailQueue do={
:global EmailQueue;