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! Link to comment https://forums.phpfreaks.com/topic/79700-solved-finding-any-character-between-d-and-d/ 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. Link to comment https://forums.phpfreaks.com/topic/79700-solved-finding-any-character-between-d-and-d/#findComment-403605 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? Link to comment https://forums.phpfreaks.com/topic/79700-solved-finding-any-character-between-d-and-d/#findComment-403625 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. Link to comment https://forums.phpfreaks.com/topic/79700-solved-finding-any-character-between-d-and-d/#findComment-403628 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.