diff options
Diffstat (limited to 'modules/regex.inc')
-rw-r--r-- | modules/regex.inc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/modules/regex.inc b/modules/regex.inc new file mode 100644 index 0000000..21c3d65 --- /dev/null +++ b/modules/regex.inc @@ -0,0 +1,17 @@ +#!/bin/ash + +# Match $1 against perl regex $2, case insensitive +regex_imatch() { + printf "%s" "$1" | grep -qPi "$2" +} + +# Escapes $1 for use in grep -E/-P, sed -r, etc. +# Pass --slash to escape '/' too. (e.g. for sed) +regex_escape() { + if [ "x$1" = "x--slash" ]; then + printf "%s" "$2" | sed 's,[][()\.^$?*+/],\\&,g' + else + printf "%s" "$1" | sed 's/[][()\.^$?*+]/\\&/g' + fi +} + |