From: Paul Hänsch Date: Tue, 14 May 2024 10:11:55 +0000 (+0200) Subject: new function RXLITERAL() for escaping regex characters X-Git-Url: http://git.plutz.net/?p=cgilite;a=commitdiff_plain;h=HEAD;ds=sidebyside new function RXLITERAL() for escaping regex characters --- 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