This is my regex:
Code: Select all
%^\\s{2}(?#company name)(\\S.*?)[ ]{3,}.*\\n\\s*(?#optional street address)(?:(\\S.*)\\s+/\\s+)?(?#city)([^/]+?),\\s*(?#state)(\\w+)\\s+(?#5 digit zip)(\\d+(?:-\\d+)?)\\s*$%mCode: Select all
%^\\s{2}(\\S.*?)[ ]{3,}.*\\n\\s*(?:(\\S.*)\\s+/\\s+)?([^/]+?),\\s*(\\w+)\\s+(\\d+(?:-\\d+)?)\\s*$%mCode: Select all
%^\s{2}(\S.*?)[ ]{3,}.*\n\s*(?:(\S.*)\s+/\s+)?([^/]+?),\s*(\w+)\s+(\d+(?:-\d+)?)\s*$%mCode: Select all
<?php
$data = file_get_contents('test1.txt');
$regex = '%^\\s{2}(\\S.*?)[ ]{3,}.*\\n\\s*(?:(\\S.*)\\s+/\\s+)?([^/]+?),\\s*(\\w+)\\s+(\\d+(?:-\\d+)?)\\s*$%m';
echo htmlentities($regex);
echo '<br /><br />';
echo htmlentities($data);
echo '<br /><br />';
preg_match_all($regex,$data,$matches);
$matches[0] = null;
print_r($matches);
?>The way I understand regex and preg_match_all is that even if there is something in that section of text that does not match, or matches from there to the end of file for instance, it should still be matching the text after. (I hope that made sense). That's why I don't think there's anything wrong with the regex... but I could be wrong.
Can anyone explain this behavior?
Thank you in advance!