summaryrefslogtreecommitdiffstats
path: root/modules/regex.inc
blob: 21c3d6512d9ae816000fb36c56acb5c7f8da44f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
}