How can I replace Html inside pre tag? I would prefer to do that with Regex
<html>
<head></head>
<body>
<div>
<pre>
<html>
<body>
-----> hello! ----<
</body>
</html
</pre>
</div>
</body>
How can I replace Html inside pre tag? I would prefer to do that with Regex
<html>
<head></head>
<body>
<div>
<pre>
<html>
<body>
-----> hello! ----<
</body>
</html
</pre>
</div>
</body>
RegEx match open tags except XHTML self-contained tags
Thank you martinho fernandes
EDIT: As indicated by another answer, regex does not support HTML or XHTML completely, and so you will be better off using an HTML parser instead. I'm leaving my answer here for reference though.
What do you want to replace the content inside the pre-tags with?
I'm not familiar with the specific C# syntax, but provided C# uses Perl-style regexes, the following PHP-snippet might be helpful. The code below will replace the content inside the pre-tags with the string "(pre tag content was here)" (just tested with the command line PHP client):
The
?
mark is to make the matching non-greedy (stop at first occurence of what comes after), and themU
modifiers specifies "Unicode-character-support" and "single-line support". The latter is important to make.
match newlines also. The[^<>]*
part is for supporting attributes in the pre tag, such as<pre class="some-css-class">
(it will match any number of characters except for<
or>
.UPDATE: As indicated by Martinho Fernandes in the comments below, the C# syntax for the above regex should be something like: