From 58a01fd257b6f190d6a44662fbd78944fbc608aa Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 27 May 2019 16:58:01 +0200 Subject: Modularize --- modules/regex.inc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 modules/regex.inc (limited to 'modules/regex.inc') 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 +} + -- cgit v1.2.3-55-g7522