php - Filename regex extraction -


i'd parts of filename

filenameblabla_2009-001_name_surname-name_surname

i'd get: 2009-001, name_surname, name_surname

i've come this, it's no good

preg_match("/(?:[0-9-]{8})_(?:[a-z_]+)-(?:[a-z_]+)/", $filename, $matches); 

any pointers?

thanks! br

assuming filename format doesn't change:

preg_match('#(\d{4}-\d{3})_(.*?)-(.*?)$#', $filename, $match); 

updated version handle extension:

preg_match('#(\d{4}-\d{3})_(.*?)-(.*?)\.(.*?)$#', $filename, $match); 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -