3
I would like to create a regular expression that searches for tags:
<b>, <p>, <i>
How would you do that in regular expression?
3
I would like to create a regular expression that searches for tags:
<b>, <p>, <i>
How would you do that in regular expression?
2
You can use the expression @"\<([\/?\s?\w]+)\>
See the example below.
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
foreach (Match match in Regex.Matches("<p> olá </ br> nova linha </p>", @"\<([\/?\s?\w]+)\>"))
{
Console.WriteLine("{0}", match.Value);
}
}
}
https://dotnetfiddle.net/2flyzC
You can do the Replace
straight with the Regex
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
string texto = "<p> olá </ br> nova linha </p>";
var match = Regex.Replace(texto, @"\<([\/?\s?\w]+)\>", "");
Console.WriteLine(match);
}
}
Browser other questions tagged c# regex
You are not signed in. Login or sign up in order to post.
Maybe you can help!
– Marconi
You want to search for what? take what’s between them? erase?
– JuniorNunes
actually delete @Juniornunes
– Evelym
delete everything inside the tag or just the tags?
– JuniorNunes
Search in a text for example the user typed <i>hello<i/> I want to locate and remove tags.
– Evelym