I want to extract certain word out of a string using regex.
I got this code now and it works perfectly when i search for *
public static string Tagify(string value, string search, string htmlTag, bool clear = false)
{
Regex regex = new Regex(@"\" + search + "([^)]*)\\" + search);
var v = regex.Match(value);
if (v.Groups[1].ToString() == "" || v.Groups[1].ToString() == value || clear == true)
{
return value.Replace(search, "");
}
return value.Replace(v.Groups[0].ToString(), "<" + htmlTag + ">" + v.Groups[1].ToString() + "</" + htmlTag + ">");
}
But now I need to search for **, but unfortunately this does not work How can I achieve this?
@"\*\*(.*?)\*\*", but the most efficient is@"\*\*([^*]*(?:\*(?!\*)[^*]*)*)\*\*"([^)]*)inside? Do you mean you want to exclude any)in between**s?