ro88o Posted December 1, 2007 Share Posted December 1, 2007 Hi, I'm trying to match comment-style blocks of text in a file using preg_match_all(). An example of what I'm trying to match is: /*D any character here including tabs, new lines, spaces etc. D*/ Up until now I'd tried "~/\*D[\w\W\s]*D\*/~" but in this situation if there was a second block of text it would match the whole thing i.e /*D test D*/ /*D test2 D*/ would be matched rather than gettin two separate matches. I had a search in the forum but the solutions in other posts concerning comments don't seem to solve my problem. Can anybody tell me the pattern I would need to match these comments? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Orio Posted December 1, 2007 Share Posted December 1, 2007 Try: <?php preg_match_all("~/\*D(.*?)D\*/~s", $str, $matches); ?> Orio. Quote Link to comment Share on other sites More sharing options...
ro88o Posted December 1, 2007 Author Share Posted December 1, 2007 Try: <?php preg_match_all("~/\*D(.*?)D\*/~s", $str, $matches); ?> Orio. Brilliant that worked thanks alot! What does the 's' do at the end? Quote Link to comment Share on other sites More sharing options...
Orio Posted December 1, 2007 Share Posted December 1, 2007 It means that the dot character will match newlines as well. Orio. 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.