I was just helped in another thread with a regex that has been verified to work. I can see it actually working on Rubular but when I plug the regex into preg_match, I get absolutely nothing.
Here is the regex with my preg_match function:
preg_match('/^!!([0-9]{5}) +.*? +[MF] ([0-9]{3})([0-9]{3})([A-Z]{3})([A-Z]{3}) + ([A-Z])[0-9]{3}([0-9]{4})([0-9]{2})([0-9]{2})/', $res, $matches);
All I am getting is an empty array returned.
The problem is that you have added two extra spaces into the regular expression that should not be there and that cause the match to fail.
/^!!([0-9]{5}) +.*? +[MF] ([0-9]{3})([0-9]{3})([A-Z]{3})([A-Z]{3}) + ([A-Z])... ^ ^ here and hereWhitespace is significant (by default) in regular expressions. A space in a regular expression matches a space in the target string. Removing these two spaces fixes the problem.
See it working on ideone (this time it is a PHP example).
array(10) { [0]=> string(39) "!!92519 C 01 M600200BLNBRN D55420090205" [1]=> string(5) "92519" [2]=> string(3) "600" [3]=> string(3) "200" [4]=> string(3) "BLN" [5]=> string(3) "BRN" [6]=> string(1) "D" [7]=> string(4) "2009" [8]=> string(2) "02" [9]=> string(2) "05" }