Regex - match exactly one tag
I have a regex to extract text from an HTML tag tag:
<FONT FACE=\"Excelsior LT Std Bold\"(.*)>(.*)</FONT>
This works fine until I have some nested font tags. Instead of matching
<FONT FACE="Excelsior LT Std Bold">Fett</FONT>
result for row
<FONT FACE="Excelsior LT Std Bold">Fett</FONT> + <U>Unterstrichen</U> + <FONT FACE="Excelsior LT Std Italic">Kursiv</FONT> und Normal
is an
<FONT FACE="Excelsior LT Std Bold">Fett</FONT> + <U>Unterstrichen</U> + <FONT FACE="Excelsior LT Std Italic"
How to get only the first tag?
<FONT[^>]*Excelsior LT Std Bold[^>]*></FONT>
Here is my use of C # for this expression. This was used to remove certain CSS and JS files from the HTTP response.
const string CSSFormat = "<link[^>]*{0}[^>]*css[^>]*>";
const string JSFormat = "<script[^>]*{0}[^>]*js[^>]*></script>";
static readonly Regex OverrideCss = new Regex(string.Format(CSSFormat, "override-"), RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline);
static readonly Regex OverrideIconsJs = new Regex(string.Format(JSFormat, "overrideicons"), RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline);