src/Context.php
public function find($re, $filter = null) {
        if ($this->isEmpty()) {
            return self::getEmptyContext();
        }

        $result = null;

        if ($filter) {
            $this->findAll($re)->each(function($context) use ($filter, &$result) {
                if ($filter($context)) {
                    $result = $context;
                    return false;
                }
            });

            return $result?:self::getEmptyContext();
        }

        if (!preg_match($re, $this->toString(), $match)) {
            return self::getEmptyContext();
        }

        return new self($match);
    }
public function find($re, $filter = null) {
        if ($this->isEmpty()) {
            return self::getEmptyContext();
        }

        $result = null;

        if ($filter) {
            $this->findAll($re)->each(function($context) use ($filter, &$result) {
                if ($filter($context)) {
                    $result = $context;
                    return false;
                }
            });

            return $result?:self::getEmptyContext();
        }

        if (!preg_match($re, $this->toString(), $match)) {
            return self::getEmptyContext();
        }

        return new self($match);
    }
public function find ( $ re , $ filter = null ) { if ( $ this -> isEmpty ( ) ) { return self :: getEmptyContext ( ) ; } $ result = null ; if ( $ filter ) { $ this -> findAll ( $ re ) -> each ( function ( $ context ) use ( $ filter , & $ result ) { if ( $ filter ( $ context ) ) { $ result = $ context ; return false ; } } ) ; return $ result ? : self :: getEmptyContext ( ) ; } if ( ! preg_match ( $ re , $ this -> toString ( ) , $ match ) ) { return self :: getEmptyContext ( ) ; } return new self ( $ match ) ; }
Find with regexp in current context
@param  string $re
@param  callable $filter
@return Context
Find with regexp in current context