Evgeniy
Evgeniy

Reputation: 75

Regex replace text between tags

How to match text between these tags ?

<!-- |IFNOT:ARCHIVE_PAGE| -->
some text
<!-- |END:IF| -->

Thanx!

Upvotes: 0

Views: 2001

Answers (4)

Harry
Harry

Reputation: 21

preg_replace("/<body>([\s\S]*.*)<\/body>/",$replace,$origional);

this will replace whole content between body tags.

Upvotes: 2

Mauritz Hansen
Mauritz Hansen

Reputation: 4774

Using Perl, the only special character here is the pipe '|'. So, the following regex will match (and return due to the capturing brackets (.+) ) the text you are looking for:

{<!-- \|IFNOT:ARCHIVE_PAGE\| -->\s*(.+)\s*<!-- \|END:IF\| -->}s

Note that the 's' modifier let's the regex match multiple lines, and the \s* before and after the capturing brackets means that whitespace (including line breaks) will not be included in the returned match.

Upvotes: 0

Sergio
Sergio

Reputation: 6948

try this regex:

(?<=<!-- \|IFNOT:ARCHIVE_PAGE\| -->)(\s|.)*?(?=<!-- \|END:IF\| -->)

Upvotes: 1

RainHeart257
RainHeart257

Reputation: 305

This is not very recommendable but

<!-- \|IFNOT:ARCHIVE_PAGE\| -->((\s|.)*?)<!-- \|END:IF\| -->

Upvotes: 2

Related Questions