I am trying to use a regex to match on a filename from the RecursiveDirectoryIterator which ends in .conf and then capture the filename and the directory (and optional sub directory it sits in).
Debugex says the capture works, but PHP is returning false, I need this to work on Windows and Linux.
I'm sure I've done something silly, any ideas what?
$indir = 'C:\Users\User\Dir1\Dir2\Dir3\Dir4\models';
$filename = 'C:\Users\User\Dir1\Dir2\Dir3\Dir4\models\product\subproduct\configuration-item.conf
// Or can be without sub product
$filename = 'C:\Users\User\Dir1\Dir2\Dir3\Dir4\models\product\configuration-item.conf
$regex = /** @lang RegExp */ "~" . addslashes($indir) . '\\*(?P<product>[^\\/]+)[\\/]*(?P<subproduct>[^\\/]*)[\\/](?P<file>.*)\.conf~';
$result = preg_match( $regex, $filename, $matches);