Regex for space, but not escaped spaces

I am parsing the input of ls -lb and trying to put each field into an array in PHP. My input looks something like this:\[code\]-rwx------ 1 user.name users 546879 2008-09-05 09:23 Newspaper_Templates.pdf-rwx------ 1 user.name users 403968 2009-01-12 14:16 P2_05.ppt-rwx------ 1 user.name users 144896 2009-01-12 14:08 P2.5_Using_CRO.pptdrwx------ 8 user.name users 4096 2009-09-15 10:21 School\ 09-10drwx------ 2 user.name users 4096 2010-06-28 13:59 SMART\ Notebookdrwx------ 2 user.name users 4096 2009-11-30 13:35 Templates\[/code\]I'm looking at each line at a time, and trying to replace multiple spaces with a single space, apart from ones that are escaped with a .Each row is read into a variable called $filedata, then put through this:\[code\] $filedata = http://stackoverflow.com/questions/3678706/preg_replace("/\s+/", " ", $filedata); print_r (preg_split("/[\s]/", $filedata));\[/code\]This almost works, but for the rows with the escaped spaces, it obviously doesn't. How can I modify this so that my split works for spaces, but not escaped spaces?(Alternatively, is there a better way? If I could get ls to give me the listing with each field seperated by a comma or something, that would be even better!)
 
Back
Top