From 31a609e61f9f400b338dc008c468ff7c07188d31 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Thu, 30 Nov 2017 15:20:06 +0100 Subject: support grep -v --- it.class | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'it.class') diff --git a/it.class b/it.class index 8e8be22..c537ae7 100644 --- a/it.class +++ b/it.class @@ -459,16 +459,17 @@ static function replace($replacements, $string, $p = array()) /** * Returns only the array elements matching the given regex - * @param $pattern Regex to match against - * @param $array array to grep + * @param $pattern Regex to match against + * @param $array array to grep + * @param $p parameters for it::match or 'invert' => true to return non-matching lines * @return New array */ static function grep($pattern, $array, $p = array()) { if (!preg_match('/\\\\[wb]|[!\x80-\xff]|\[\[:/i', $pattern) && !$p) - $result = preg_grep('!' . $pattern . '!i' . (ini_get('default_charset') == 'utf-8' ? 'u' : ''), $array); # fast path for simple patterns + $result = preg_grep('!' . $pattern . '!i' . (ini_get('default_charset') == 'utf-8' ? 'u' : ''), $array, $p['invert'] ? PREG_GREP_INVERT : 0); # fast path else - $result = preg_grep(it::convertregex($pattern, $p), $array); + $result = preg_grep(it::convertregex($pattern, $p), $array, $p['invert'] ? PREG_GREP_INVERT : 0); return $result; } -- cgit v1.2.3