From 7f444e3275361651eb5e0b89f09fd3afd8113e9f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 14 May 2024 12:11:55 +0200 Subject: [PATCH] new function RXLITERAL() for escaping regex characters --- storage.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/storage.sh b/storage.sh index 17ea0d0..5c61df0 100755 --- a/storage.sh +++ b/storage.sh @@ -94,6 +94,21 @@ UNSTRING(){ printf '%s\n' "$out" } +RXLITERAL(){ + # sed -E 's;[].*+?^${}()|\[];\\&;g' + local in out='' + [ $# -gt 0 ] && in="$*" || in="$(cat)" + while [ "$in" ]; do case $in in + [.+^\$\{\}\(\)\[\]\*\?\|\\]*) + out="${out}\\${in%"${in#?}"}"; in="${in#?}"; + ;; + *)out="${out}${in%%[.+^\$\{\}\(\)\[\]\*\?\|\\]*}" + in="${in#"${in%%[.+^\$\{\}\(\)\[\]\*\?\|\\]*}"}" + ;; + esac; done + printf '%s\n' "$out" +} + DBM() { local file="$1" cmd="$2" local k v key value -- 2.39.2