asp.net - Using Regex in C# -


using regex let have html string how can widgets control tag 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 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" /> 

list<string> widgets = new list<string>();  matchcollection matches = regex.matches(yourhtmlcode, "<widget:([^/][^>])*/>"); foreach (match match in matches) {     foreach (capture capture in match.captures)     {         widgets.add(capture.value);     } } 

source: http://www.dotnetperls.com/regex-matches


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -