@param string $regex
@param string attr

@return array
776262
public function images($regex = null, $attr = 'src')
    {
        /**
         * @var \DOMElement $node
         */
        $document = $this->_document;
        $data = [];
        foreach ($document->getQuery()->xpath("descendant::img[@$attr]", $this->_node) as $node) {
            $src = $document->absolutizeUrl($node->getAttribute($attr));

            if ($regex && !preg_match($regex, $src)) {
                continue;
            }

            $data[$node->getNodePath()] = $src;
        }

        return $data;
    }
709312
public function whereRegex($field, $regex, $flags = '')
    {
        foreach ($this->queries as $query) {
            $query->whereRegex($field, $regex, $flags);
        }

        return $this;
    }
560117
public function getFolders($regex = null, $recursive = false)
    {
        //argument test
        Argument::i()
            //argument 1 must be a string
            ->test(1, 'string', 'null')
            //argument 2 must be a boolean
            ->test(2, 'bool');

        $this->absolute();

        $folders = array();

        if ($handle = opendir($this->data)) {
            //walk the directory
            while (false !== ($folder = readdir($handle))) {
                // If this is infact a directory
                //and if it matches the regex
                if ($folder != '.' && $folder != '..'
                      && filetype($this->data .'/'. $folder) == 'dir'
                    && (!$regex || preg_match($regex, $folder))) {
                    //add it
                    $folders[] = self::i($this->data . '/' . $folder);
                    if ($recursive) {
                        $subfolders = self::i($this->data.'/'.$folder);
                        $folders = array_merge($folders, $subfolders->getFolders($regex, $recursive));
                    }

                }
            }
            closedir($handle);
        }

        return $folders;
    }
974775
private function getMatchingData(array $params, $regex)
    {
        foreach ($params as $data) {
            if (preg_match($regex, $data)) {
                return $data;
            }
        }

        return '';
    }
508640
function (attrString) {
    var tokens = {};

    // Regex for parsing a css attribute declaration, taken from css-parse:
    // https://github.com/reworkcss/css-parse/blob/7cef3658d0bba872cde05a85339034b187cb3397/index.js#L219
    var regex = /(\*?[-#\/\*\\\w]+(?:\[[0-9a-z_-]+\])?)\s*:\s*(?:\'(?:\\\'|.)*?\'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+[;\s]*/g;
    var match = regex.exec(attrString);
    while (match) {
      // match[0] = entire matching string
      // match[1] = css property
      // Prefix the token to prevent conflicts with existing properties.

      // XXX No `String.trim` on Safari 4. Swap out $.trim if we want to
      // remove strong dep on jquery.
      tokens[' ' + match[1]] = match[0].trim ?
        match[0].trim() : $.trim(match[0]);

      match = regex.exec(attrString);
    }

    return tokens;
  }
631975
public function getMethodsByPattern($regex)
    {
    	$methods    = parent::getMethods();
    	$moufMethods = array();
    	foreach ($methods as $method) {
    		if (preg_match("/$regex/", $method->getName())) {
    			$moufMethods[$method->getName()] = new MoufReflectionMethod($this, $method->getName());
    		}
    	}
    
    	return $moufMethods;
    }
1257927
protected function convertAttributeValueTemplate($attrValue)
	{
		$phpExpressions = [];
		foreach (AVTHelper::parse($attrValue) as $token)
		{
			if ($token[0] === 'literal')
			{
				$phpExpressions[] = var_export($token[1], true);
			}
			else
			{
				$phpExpressions[] = $this->convertXPath($token[1]);
			}
		}

		return implode('.', $phpExpressions);
	}
717178
private function replaceTokensWithRegexCaptureGroups($regex)
    {
        $tokenRegex = self::TOKEN_REGEX;

        return preg_replace_callback(
            self::PLACEHOLDER_REGEXP,
            array($this, 'replaceTokenWithRegexCaptureGroup'),
            $regex
        );
    }
1369780
public function getAllValues(array $array, string $regex)
    {
        $result = [];

        foreach ($array as $key => $value) {
            if (preg_match('/' . $regex . '/', $key)) {
                $result[ $key ] = $value;
            }
        }

        return $result;
    }
185330
public static function ruleRegexInverse($regex)
    {
        $args = func_get_args();
        $regex = join(':', $args);

        /*not in format "/../<modifier>", "#..#<modifier>"  nor "~..~<modifier>" */
        if (!preg_match('/^([\/#~]).+\1[msugex]*$/', $regex)) {
            $regex = '/'. stripslashes($regex). '/';
        }

        return function ($input) use ($regex) {
            return !preg_match($regex, $input);
        };
    }
540268
public static function ruleRegex($regex)
    {
        $args = func_get_args();
        $regex = join(':', $args);

        /*not in format "/../<modifier>", "#..#<modifier>"  nor "~..~<modifier>" */
        if (!preg_match('/^([\/#~]).+\1[msugex]*$/', $regex)) {
            $regex = '/'. stripslashes($regex). '/';
        }

        return function ($input) use ($regex) {
            return preg_match($regex, $input);
        };
    }
316720
private function parse_attributes($attr)
    {
        $html = '';

        if (!empty($attr)) {
            $html = '';

            foreach ($attr as $key => $value) {
                $html .= \sprintf('%s="%s" ', $key, \esc_attr($value));
            }
        }

        return \trim($html);
    }
984949
protected static function replaceWildcards($regex)
    {
        preg_match_all(chr(1) . '\(\\*([a-z][a-zA-Z0-9]*)\)' . chr(1), $regex, $matches, PREG_SET_ORDER);

        foreach ($matches as $match) {
            $name = $match[1];

            $regex = str_replace("(*{$name})", "(?P<{$name}>.*)", $regex);
        }

        return $regex;
    }
256843
public function pregSplit(string $regex, int $limit = -1): StreamInterface
    {
        $strings = \preg_split($regex, $this->value, $limit);
        $stream = new Stream(self::class);

        foreach ($strings as $string) {
            $stream = $stream->add(new self($string, $this->encoding));
        }

        return $stream;
    }
91568
public function responseMatches($regex)
    {
        $actual = $this->session->getPage()->getContent();
        $message = sprintf('The pattern %s was not found anywhere in the HTML response of the page.', $regex);

        $this->assert((bool) preg_match($regex, $actual), $message);
    }
1228239
public function regexp($field, $regex, array $attributes = [])
    {
        $query = new RegexpQuery($field, $regex, $attributes);

        $this->append($query);

        return $this;
    }
1065532
public function add($attrName, $regexp)
	{
		$attrName = AttributeName::normalize($attrName);

		$k = serialize([$attrName, $regexp]);
		$this->items[$k] = new AttributePreprocessor($regexp);

		return $this->items[$k];
	}