michaellunsford Posted January 4, 2008 Share Posted January 4, 2008 So I have a long string that I need to break into an array. One nasty field has spaces in it. I need to capture the single spaces, but stop at the first occurrence of a double-space. ([A-Z0-9]+)[\s]+([^\s{2}]+) just doesn't do it. Here's an example of the input: 634RA32 SOME STRING WITH SPACES B 250 0 N Any ideas? Quote Link to comment Share on other sites More sharing options...
effigy Posted January 4, 2008 Share Posted January 4, 2008 <pre> <?php $str = '634RA32 SOME STRING WITH SPACES B 250 0 N'; print_r(preg_split('/\s{2,}/', $str)); ?> </pre> Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 4, 2008 Author Share Posted January 4, 2008 ahhhhhh preg_split. I forgot about preg_split! Quote Link to comment Share on other sites More sharing options...
effigy Posted January 4, 2008 Share Posted January 4, 2008 The non-split solution: <pre> <?php $str = '634RA32 SOME STRING WITH SPACES B 250 0 N'; preg_match_all('/\b(??!\s{2,}).)+/', $str, $matches); print_r($matches); ?> </pre> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.