Brandon_R Posted August 3, 2009 Share Posted August 3, 2009 Hello guys im looking for a regular expression that would match everything between 2 tags and replace it with nothing. Something like <!-- open tag --> <a href="http://www.phpfreaks.com>PHP Freaks</a> <!-- / open tag --> I need an expression that would match ANYTHING (even whitespaces etc) that is between the open tag (or any tag i specify). Thank You, Brandon_R Link to comment https://forums.phpfreaks.com/topic/168672-regex-to-match-everything-between-2-tags/ Share on other sites More sharing options...
Garethp Posted August 4, 2009 Share Posted August 4, 2009 preg_replace('/<\!-- open tag -->(.*?)<\!-- \/ open tag -->/', '', $String); Link to comment https://forums.phpfreaks.com/topic/168672-regex-to-match-everything-between-2-tags/#findComment-890393 Share on other sites More sharing options...
Adam Posted August 4, 2009 Share Posted August 4, 2009 If you want to match everything, I'd add the 's' modifier to match new lines as well: /<\!-- open tag -->(.*?)<\!-- \/ open tag -->/s Link to comment https://forums.phpfreaks.com/topic/168672-regex-to-match-everything-between-2-tags/#findComment-890397 Share on other sites More sharing options...
Brandon_R Posted August 6, 2009 Author Share Posted August 6, 2009 Thanks Guys Brandon_R Link to comment https://forums.phpfreaks.com/topic/168672-regex-to-match-everything-between-2-tags/#findComment-891983 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.