using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(<.*?(?=mensagem).*?>)(.*?)(<.*?>)|(.*)";
string substitution = @"$2";
string input = @"<span id=""mensagem"" class=""topo"">Classes e comandos</span>
<sfdfsdpan id=""mendsagem"" class=""topo"">Classes e comandos</span>
<s4856461pan id=""mensagem"" class=""topo"">AAAAAA</span>
<span id=""meaaaaansagem"" class=""topo"">VOU APRENDER REGEX</span>
<span id=""mensagem"" class=""topo"">H1234Ç.,w^</span>
<span id=""mensagem"" class=""topo"">VOU APRENDER REGEX</span>
";
Regex regex = new Regex(pattern);
string result = regex.Replace(input, substitution);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx