Returns an array of all matching files in current directory.

@param string $regexpPattern Preg_match pattern (Defaults to: .*)
@param bool $sort Whether results should be sorted.
@return array Files that match given pattern
426714
public function find($regexpPattern = '.*', $sort = false)
    {
        list(, $files) = $this->read($sort);

        return array_values(preg_grep('/^' . $regexpPattern . '$/i', $files));
    }
478898
public static function getStringElements($string, $separator)
    {
        $matches = [];
        $pattern = sprintf('|[^\%s]+|', $separator);
        $matchCount = preg_match_all($pattern, $string, $matches);

        if ($matchCount > 1) {
            return $matches[0];
        }

        return [];
    }
748438
def file_matches_regexps(filename, patterns):
    """"""
    return any(re.match(pat, filename) for pat in patterns)
585320
private function listAllFiles($folder, $extension = '*')
    {
        /**
         * @var array<mixed, string> $fileList
         * @var string $i
         * @var string $file
         * @var \RecursiveDirectoryIterator $dir
         * @var \RecursiveIteratorIterator $ite
         */
        $dir = new \RecursiveDirectoryIterator($folder);
        $ite = new \RecursiveIteratorIterator($dir);
        if ($extension === '*') {
            $pattern = '/.*/';
        } else {
            $pattern = '/.*\.' . $extension . '$/';
        }
        $files = new \RegexIterator($ite, $pattern, \RegexIterator::GET_MATCH);

        /** @var array<string, string> $fileList */
        $fileList = [];

        /**
         * @var string $fileSub
         */
        foreach($files as $fileSub) {
            $fileList = \array_merge($fileList, $fileSub);
        }

        /**
         * @var string $i
         * @var string $file
         */
        foreach ($fileList as $i => $file) {
            if (\preg_match('#/\.{1,2}$#', (string) $file)) {
                unset($fileList[$i]);
            }
        }
        return \array_values($fileList);
    }
423806
public function getFiles(string $location, string $pattern = null, Finder $finder = null): array
    {
        $finder = $finder ?? new Finder();
        $finder->files()->in($location);

        if (!empty($pattern)) {
            $finder->name($pattern);
        }

        $result = [];
        foreach ($finder->getIterator() as $file) {
            $result[] = $this->normalizePath((string)$file);
        }

        return $result;
    }
353919
public function glob($pattern = '*', $flag = 0) {
        $files = [];
        foreach (glob($this->fullName.'/'.$pattern, $flag) as $item) {
            if (is_dir($item)) {
                $files[] = new static($item);
                continue;
            }
            $files[] = new File($item);
        }
        return $files;
    }
1116325
public function getMatch(string $pattern, int $flags = 0, int $offset = 0)
	{
		return preg_match($pattern, $this->str, $matches, $flags, $offset) === false ? null : $matches;
	}
852972
public function GetFiles($pattern = "")
	{
		$files = Array();
		$dh = opendir($this->Path);

		while ($fname = readdir($dh)) 
		{
			if (is_file($this->Path.$fname))
			{
				if ($pattern == "" || preg_match($pattern,$fname) > 0)
				{
					$files[] = new FileHelper($this->Path.$fname);
				}
			}
		}
		
		closedir($dh);
	    
		return $files;
	}
371831
public static function parseExtensions($extensions, $trimPattern = ". \t\n\r\0\x0B")
    {
        $parsed = [];
        $extensions = is_string($extensions) ? explode('|', $extensions) : (array) $extensions;
        foreach ($extensions as $extension) {
            if (is_string($extension)) {
                $extension = strtolower(trim($extension, $trimPattern));
                in_array($extension, $parsed, true) or $parsed[] = $extension;
            }
        }

        return $parsed;
    }
865929
public function findTemplates(string $path, string $pattern = null, string $format = 'twig')
    {
        // Use glob() if possible
        if (false === strpos($path, '/**/') && (\defined('GLOB_BRACE') || false === strpos($path, '{'))) {
            $templates = glob(rtrim($path, '/').'/*.{'.$format.'}', \defined('GLOB_BRACE') ? GLOB_BRACE : 0);

            return null === $pattern ? $templates : preg_grep('$'.$pattern.'$', $templates);
        }

        $pattern = rtrim($path, '/').(null === $pattern ? '' : $pattern).'/*.{'.$format.'}';

        $finder = new Finder();
        $regex = Glob::toRegex($pattern);

        // All files in the given template folder
        $filesIterator = $finder->files()->followLinks()->sortByName()->in(\dirname($pattern));

        // Match the actual regex and filter the files
        $filesIterator = $filesIterator->filter(
            function (\SplFileInfo $info) use ($regex) {
                $path = $info->getPathname();

                return preg_match($regex, $path) && $info->isFile();
            }
        );

        $files = iterator_to_array($filesIterator);

        return array_keys($files);
    }
301996
public static function regexContains($string, $find)
    {
        if (is_array($find)) {
            foreach ($find as $part) {
                if (preg_match($part, $string)) {
                    return true;
                }
            }

            return false;
        } else {
            return (preg_match($find, $string));
        }
    }
782358
public function IsFolderMatchingFilter($path, $regexFilter) {
        return \Puzzlout\Framework\Helpers\RegexHelper::Init($path)->IsMatch($regexFilter);
    }
84727
public static List<File> listFileWithRegexFileName(final File rootDir, final String regexFileNamePattern) {
		return Files.fileTreeTraverser().preOrderTraversal(rootDir)
				.filter(new RegexFileNameFilter(regexFileNamePattern)).toList();
	}
423013
public function match($regexp, $flag = PREG_PATTERN_ORDER, $offset = 0)
    {
        if ((bool) preg_match_all($regexp, $this->subject, $matches, $flag, $offset) === false) {
            return;
        }

        return $matches;
    }
962629
public static File[] findMatches( File directory , String regex ) {
		final Pattern p = Pattern.compile(regex); // careful: could also throw an exception!
		return directory.listFiles(file -> p.matcher(file.getName()).matches());
	}
42949
public function listFiles($regexFilter = null)
    {
        $filesList = [];
        if ($regexFilter) {
            $filter = function ($file) use (&$filesList, $regexFilter) {
                // push/pop an error handler here to to make sure no error/exception thrown if $expected is not a regex
                set_error_handler(function () {
                });
                $match = preg_match($regexFilter, $file);
                restore_error_handler();

                if ($match === 1) {
                    $filesList[] = $file;
                } elseif ($match === false) {
                    throw new \RuntimeException("regular expression match on '$file' failed with error. Please check if pattern is valid regular expression.");
                }
            };
        } else {
            $filter = function ($file) use (&$filesList) {
                $filesList[] = $file;
            };
        }
        $this->repository->each($filter);

        return $filesList;
    }
1247363
protected function sort(array &$files, $sort, $order)
    {
        $sorters = $this->getSorters();

        if (isset($sorters[$sort]['handlers']['sort'])) {
            $function = $sorters[$sort]['handlers']['sort'];
            // Suppress errors, see https://bugs.php.net/bug.php?id=50688
            @uasort($files, function ($a, $b) use ($function, $order) {
                return $function($a, $b, $order);
            });
        }
    }