What are some potential pitfalls of using regular expressions in PHP for file matching and retrieval?

One potential pitfall of using regular expressions in PHP for file matching and retrieval is that it can be error-prone, especially for complex patterns. To avoid this, it's recommended to use built-in functions like glob() or scandir() for simpler file matching tasks. Additionally, it's important to properly handle errors and edge cases when using regular expressions for file retrieval to ensure robustness.

// Example of using glob() for file matching and retrieval
$files = glob('/path/to/files/*.txt');
foreach ($files as $file) {
    echo $file . "\n";
}