summaryrefslogblamecommitdiffstats
path: root/modules/regex.inc
blob: 3188b2dfb196cb6d5f56a01a8d00d54a25ef2c24 (plain) (tree)
1
2
3
4
5
6
7

          




                                                














                                                               
#!/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
}