#!/bin/ash # Match $1 against perl regex $2, case sensitive regex_match() { printf "%s" "$1" | grep -qP "$2" } # 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 }