G
Guest
I am trying to strip the outermost html tag by capturing this tag with regex
and then using the string replace function to replace it with an empty
string. while stepping through the code, RegEx returns the entire input
string although testing this in The Regulator returns just what I want.
What am I doing wrong here?
***********************************************
Regex regX;
RegexOptions options = (RegexOptions.Multiline | RegexOptions.IgnoreCase);
Match rMatch;
string sX,sTag;
string regexOpening = "(?:^)(<[a-zA-Z]*\\s*[a-zA-Z0-9=\'\" ]*>).*$";
string regexClosing = "(<\\s*/[a-zA-Z0-9]*\\s*>)\\s*$\r\n";
//code removed for clarity: return a datareader here...
{
while(r.Read()){
sX = r["HeaderHTML"].ToString().Trim();
regX = new Regex(regexOpening,options);
rMatch= regX.Match(sX);
sTag = rMatch.Value.ToString(); //this returns the entire string!!
sX = sX.Replace(sTag,"");
some sample input:
1. <TH colspan=2 align="left"><IMG src="Images/KCbanner_header.jpg"
width="800" height="90"></TH>
and then using the string replace function to replace it with an empty
string. while stepping through the code, RegEx returns the entire input
string although testing this in The Regulator returns just what I want.
What am I doing wrong here?
***********************************************
Regex regX;
RegexOptions options = (RegexOptions.Multiline | RegexOptions.IgnoreCase);
Match rMatch;
string sX,sTag;
string regexOpening = "(?:^)(<[a-zA-Z]*\\s*[a-zA-Z0-9=\'\" ]*>).*$";
string regexClosing = "(<\\s*/[a-zA-Z0-9]*\\s*>)\\s*$\r\n";
//code removed for clarity: return a datareader here...
{
while(r.Read()){
sX = r["HeaderHTML"].ToString().Trim();
regX = new Regex(regexOpening,options);
rMatch= regX.Match(sX);
sTag = rMatch.Value.ToString(); //this returns the entire string!!
sX = sX.Replace(sTag,"");
some sample input:
1. <TH colspan=2 align="left"><IMG src="Images/KCbanner_header.jpg"
width="800" height="90"></TH>