using regex let say I have html as string How can I get all widgets control tag from string using regex.?
Current Approach
const string widgetStartPattern = "<widget:ContentPageView";
const string widgetEndPattern = "/>";
var allOccuranceOfWidgets = CountStringOccurrences(aspx, widgetStartPattern);
while (allOccuranceOfWidgets.Count > 0)
{
var firstIndex = allOccuranceOfWidgets[0];
var lastIndex = aspx.IndexOf(widgetEndPattern, firstIndex + 1, System.StringComparison.OrdinalIgnoreCase);
var widgetUserControlTag = aspx.Substring(firstIndex, lastIndex - firstIndex + 2);
var pageId = ExtractPageIdFromWidgetTag(widgetUserControlTag);
var pageContent = GetContentFromaDatabase(pageId);
aspx = aspx.Replace(widgetUserControlTag, pageContent);
allOccuranceOfWidgets = CountStringOccurrences(aspx, widgetStartPattern);
}
Result list of all widgets control
<widget:ContentPageView id="ContentPageView0" PageId="165" runat="server" />
<widget:ContentPageView id="ContentPageView1" PageId="166" runat="server" />
<widget:ContentPageView id="ContentPageView2" PageId="167" runat="server" />
HTML
<div class="slogan">
<widget:ContentPageView id="ContentPageView0" PageId="165" runat="server" />
</div>
<div class="headertopright">
<div class="headersocial">
<widget:ContentPageView id="ContentPageView1" PageId="166" runat="server" />
</div>
<div class="searchbox">
<widget:ContentPageView id="ContentPageView2" PageId="167" runat="server" />