lindm Posted June 30, 2010 Share Posted June 30, 2010 Need help figuring out the expression to split the following string in the two first spaces: #TEXT1 1234 "Text text text text" Should become: #TEXT1 1234 Text text text text Quote Link to comment Share on other sites More sharing options...
salathe Posted June 30, 2010 Share Posted June 30, 2010 Your example output is does not reflect the description... what happened to the double-quotes around the Text text text text part? Also, just to clarify, do you only ever want to split on the first two spaces, or do you want to split on any spaces except those within double-quote delimited phrases? Quote Link to comment Share on other sites More sharing options...
lindm Posted June 30, 2010 Author Share Posted June 30, 2010 Preferably the double quotes should be removed. As for your suggestions the best would be only the first two spaces would be the best split solution. Quote Link to comment Share on other sites More sharing options...
salathe Posted June 30, 2010 Share Posted June 30, 2010 In that case you don't need regular expressions. explode(' ', $string, 3) would split the string into, at most, 3 parts. Quote Link to comment Share on other sites More sharing options...
lindm Posted June 30, 2010 Author Share Posted June 30, 2010 Aa alright. Just curious your second suggestion: split on any spaces except those within double-quote delimited phrases, is that a simple regex? Quote Link to comment Share on other sites More sharing options...
salathe Posted June 30, 2010 Share Posted June 30, 2010 is that a simple regex? No. 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.