diff options
author | Urban Müller | 2017-11-30 15:20:06 +0100 |
---|---|---|
committer | Urban Müller | 2017-11-30 15:20:06 +0100 |
commit | 31a609e61f9f400b338dc008c468ff7c07188d31 (patch) | |
tree | cff29bf6b83f77b4cb2b7cf1f85154830b622dca /it.class | |
parent | 1c08b5b21792e5d8b8c44c13b0cddf36ef950db7 (diff) | |
download | itools-31a609e61f9f400b338dc008c468ff7c07188d31.tar.gz itools-31a609e61f9f400b338dc008c468ff7c07188d31.tar.bz2 itools-31a609e61f9f400b338dc008c468ff7c07188d31.zip |
support grep -v
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -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; } |