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 Quote 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); Quote 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 Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.