Good Day,
I have some HTML input that I want to do a search and replace operation.
string html = @"
<div class=""left bottom-margin"">
<input id=""0086"" maxlength=""29"" data-src=""200:80"" type=""text""><br />
<input id=""0087"" maxlength=""38"" data-src=""201:80"" type=""text""><br />
<input id=""0088"" maxlength=""38"" data-src=""202:80"" type=""text""><br />
</div>";
// Here we call Regex.Match.
Match match = Regex.Match(html, @"(<input.*id=""0087"".*?>)", RegexOptions.IgnoreCase);
// Here we check the Match instance.
if (match.Success)
{
// Finally, we get the Group value and display it.
string key = match.Groups[1].Value;
Console.WriteLine(key);
} else {
Console.WriteLine("No Match...");
}
This code does work, so far, but I want to be able to provide a parameter to the Regex.Match initialization. Is this possible? What if I wanted to search for 0086 or 0088 as the id? I have a couple hundred tags like this where I want to be able to find the HTML tag by providing a parameter?
I understand that the @ makes the string verbatim.
But I've tried doing this:
// string pattern = "(<input.*id=\"\"0087\"\".*?>)";
// string pattern = "(<input.*id=\"\"" + "0087" + "\"\".*?>)";
This doesn't work either. Most of the Regex.Match samples I've seen use the @ verbatim symbol to do the actual matching. Is my understanding of this correct?
Any suggestions?