@param string $field
@param string $regex
@param string $flags

@return static
505154
public function whereNotRegex($field, $regex, $flags = '')
    {
        $this->_filters[] = [$field => ['$not' => new Regex($regex, $flags)]];

        return $this;
    }
963086
static function from ($path, $flags = 4096)
  {
    try {
      return new static (new FilesystemIterator($path, $flags));
    }
    catch (\Exception $e) {
      // Convert UnexpectedValueException to another type to prevent problems with some error handlers.
      throw new \InvalidArgumentException($e->getMessage ());
    }
  }
627686
function(regex){
		//if it isn't global, `exec()` will not start at `lastIndex`
		if(!regex.global)
			regex.compile(regex.source, flags(regex));
		regex.lastIndex = this.position;
		var m = regex.exec(this.source);

		//all matches must start at the current position.
		if(m && m.index!=this.position){
			return null;
		}

		if(m) this.position += m[0].length;
		return m;
	}
486677
public function setPathRegex($regex)
    {
        if ($regex === null) {
            $this->pathRegex = null;
            return $this;
        }

        $this->pathRegex = $regex;
        return $this;
    }
378526
protected static function _check($check, $regex)
	{
		if (is_string($regex) && preg_match($regex, $check))
		{
			return true;
		}
		return false;
	}
1189932
def visit_regex(self, node, regex):
        """"""
        tilde, literal, flags, _ = regex
        flags = flags.text.upper()
        pattern = literal.literal  # Pull the string back out of the Literal
                                   # object.
        return Regex(pattern, ignore_case='I' in flags,
                              locale='L' in flags,
                              multiline='M' in flags,
                              dot_all='S' in flags,
                              unicode='U' in flags,
                              verbose='X' in flags,
                              ascii='A' in flags)
947165
public static function sortHeaders($messages, $field, $flag)
    {
        // Strategy: First, we'll create an "index" array.
        // Then, we'll use sort() on that array, and use that to sort the main array.

        $field  = empty($field) ? 'uid' : strtolower($field);
        $flag   = empty($flag) ? 'ASC' : strtoupper($flag);
        $index  = array();
        $result = array();

        reset($messages);

        foreach ($messages as $key => $headers) {
            $value = null;

            switch ($field) {
            case 'arrival':
                $field = 'internaldate';
            case 'date':
            case 'internaldate':
            case 'timestamp':
                $value = rcube_utils::strtotime($headers->$field);
                if (!$value && $field != 'timestamp') {
                    $value = $headers->timestamp;
                }

                break;

            default:
                // @TODO: decode header value, convert to UTF-8
                $value = $headers->$field;
                if (is_string($value)) {
                    $value = str_replace('"', '', $value);
                    if ($field == 'subject') {
                        $value = preg_replace('/^(Re:\s*|Fwd:\s*|Fw:\s*)+/i', '', $value);
                    }

                    $data = strtoupper($value);
                }
            }

            $index[$key] = $value;
        }

        if (!empty($index)) {
            // sort index
            if ($flag == 'ASC') {
                asort($index);
            }
            else {
                arsort($index);
            }

            // form new array based on index
            foreach ($index as $key => $val) {
                $result[$key] = $messages[$key];
            }
        }

        return $result;
    }
1053369
public static function globBrace( $pattern, $flags = 0 )
    {
        if ( defined( 'GLOB_BRACE' ) )
        {
            $flags = $flags | GLOB_BRACE;
            return glob( $pattern, $flags );
        }
        else
        {
            $result = array();
            $files = self::simulateGlobBrace( array( $pattern ) );
            foreach( $files as $file )
            {
                $globList = glob( $file, $flags );
                if ( is_array( $globList ) )
                {
                    $result = array_merge( $result, $globList );
                }
            }
            return $result;
        }
    }
261636
protected function pregMatchArray($input, $rules, $flags = 0)
    {
        if (!is_array($rules)) {
            return false;
        }

        foreach ($rules as $rule => $value) {
            if (preg_match($rule, $input, $matches, $flags)) {
                return array_merge($matches, ['value' => $value]);
            }
        }

        return false;
    }
1361698
public static function searchFile($root, $pattern = '*', $flags = 0)
    {
        $dirs = self::listDirs($root);
        array_unshift($dirs, $root);
        
        $foundFiles = [];
        
        if ($pattern instanceof \Closure) {
            $closure = $pattern;
            $pattern = '*';
        } else {
            $closure = null;
        }
        
        foreach ($dirs as $dir) {
            $filePatt = $dir . '/' . $pattern;
            $files = glob($filePatt, $flags);
            
            if ($closure) {
                foreach ($files as $file) {
                    if ($closure($file)) {
                        $foundFiles[] = $file;
                    }
                }
            } else {
                if ($files) {
                    $foundFiles = array_merge($foundFiles, $files);
                }
            }
        }
        
        return $foundFiles;
    }
402285
public function get($key, array $flags = null)
    {
        try {
            $node = $this->getNode($key, $flags);

            return $node['value'];
        } catch (KeyNotFoundException $ex) {
            throw $ex;
        }
    }
640299
public function _deleteByRegex( $regex, $fname = false )
    {
        if ( $fname )
            $fname .= "::_deleteByRegex($regex)";
        else
            $fname = "_deleteByRegex($regex)";
        return $this->_protect( array( $this, '_deleteByRegexInner' ), $fname,
                                $regex, $fname );
    }
1277247
public static function ReplaceWithFlags( $arg1, $arg2, $replacement, $flagString )
	{
		$input = $arg1 instanceof Undefined
		    ? ""
		    : $arg1 . "";

		if ( $arg2 instanceof Undefined )
		    throw XPath2Exception::withErrorCodeAndParams( "XPTY0004", Resources::XPTY0004, array( "empty-sequence()", "xs:string in fn:replace" ) );

	    $flagString = ExtFuncs::PrepareRegexFlags( $flagString );
	    $pattern = ExtFuncs::PrepareRegexPattern( $arg2 . "", $flagString );

		if ( ! ExtFuncs::IsValidReplacementString( $replacement ) )
		    throw XPath2Exception::withErrorCodeAndParam( "FORX0004", Resources::FORX0004, $replacement );

		if (  preg_match( "/$pattern/", "" ) )
		{
			throw XPath2Exception::withErrorCodeAndParam( "FORX0003", Resources::FORX0003, $pattern );
		}

		return preg_replace( "/$pattern/$flagString", ExtFuncs::UnescapeReplacementString( $replacement ), $input );
	}
572134
public static function split(string $pattern, string $input, int $size = null, int $flags = 0): array
    {
        if ($pattern[0] != '~') {
            $pattern = '~\s*'. trim($pattern, '~') .'\s*~'; // make re pattern
        }

        $ret = (array) preg_split($pattern, $input, ($size = $size ?? -1), $flags += PREG_SPLIT_NO_EMPTY);

        // prevent "undefined index ..."
        if ($size != -1 && sizeof($ret) < $size) {
            $ret = array_pad($ret, $size, null);
        }

        return $ret;
    }
831012
public function capture(string $regex): MapInterface
    {
        if (\func_num_args() !== 1) {
            throw new LogicException('Offset and flags are no longer supported');
        }

        return RegExp::of($regex)->capture($this);
    }
560815
public function orWhereLike($field, $value, $flags = 'imxsu', $delimiter = null)
    {
        return $this->whereLike($field, $value, $flags, $delimiter, '$or');
    }
802677
public function matchHost($pattern, &$matches = null, $flags = 0, $offset = 0)
	{
		return preg_match($pattern, $this->_host ?: '', $matches, $flags, $offset);
	}