Note that there are some explanatory texts on larger screens.

plurals
  1. PORegex to get HTML between two specific strings
    primarykey
    data
    text
    <p>I am not very well-versed in regular expressions, but I am trying to accomplish something in ASP.Net which I think requires them.</p> <p>I am pulling in an HTML file, doing some processing, and outputting new "merged" html. The portion I am struggling with is grabbing a chunk of code located between two predefined "tags" of my own creation.</p> <p>Here is an example of the relevant input html:</p> <pre><code>&lt;table style="width: 500px; font-family: Trebuchet MS, sans-serif; font-size: 13px; background-color: #fff; border: 0; border-collapse: collapse;" align="center" cellspacing="0"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th colspan="3" style="text-align: left;border-bottom: 1px solid #DDDDDD;"&gt; Add-ons &lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; [AddonsListSTART] &lt;tr style="border-bottom: 1px dashed #DDDDDD;"&gt; &lt;td&gt;[AddonName]&lt;/td&gt; &lt;td&gt;[AddonQty]&lt;/td&gt; &lt;td align="right"&gt;[AddOnPrice]&lt;/td&gt; &lt;/tr&gt; [AddonsListEND] &lt;/tbody&gt; &lt;/table&gt; &lt;br /&gt; </code></pre> <p>This is my C# code:</p> <pre><code>//Find Add-ons HTML : between [AddonsListSTART] &amp; [AddonsListEND] Regex rgxAddonSE = new Regex(@"\[AddonsListSTART\](?&lt;MyHtml&gt;.*)\[AddonsListEND\]"); Match matchAddonSE = rgxAddonSE.Match(htmlEmail); string htmlAddons = matchAddonSE.ToString(); </code></pre> <p>What I want to happen is for "htmlAddons" to be equal to the string:</p> <pre><code>&lt;tr style="border-bottom: 1px dashed #DDDDDD;"&gt; &lt;td&gt;[AddonName]&lt;/td&gt; &lt;td&gt;[AddonQty]&lt;/td&gt; &lt;td align="right"&gt;[AddOnPrice]&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>The problem is that it is always blank, and "matchAddonSE.Success" is always FALSE. I know there is something wrong with my regex, but I can't figure out what.</p> <p>Thank you in advance for any help.</p> <p>Heather</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload