title: Remove non-HTML special tags from text
body: <p>I'm having problem with matching <strong>non-HTML</strong> tags in text mainly, because tags starts with <code>&amp;lt;</code> and ends with <code>&amp;gt;</code> but not <code>&lt;</code> and <code>&gt;</code>. So instead <code>&lt;ref&gt;xx&lt;/ref&gt;</code> i have <code>&amp;lt;ref&amp;gt;xxx&amp;lt;/ref&amp;gt;</code>. What I need to do is remove all such tags including their content.</p>
  
  <p>The problem is that some tags may have attributes. I found nice answer <a href="https://stackoverflow.com/questions/200525/regex-for-specifig-tags-and-their-content-groupped-by-the-tag-name/200703#200703">here</a> but still there's a problem.</p>
  
  <p>Assuming that I have tag like: <code>&lt;gallery src=sss&gt;xxx&lt;/gallery&gt;</code> this expression suits perfect:</p>
  
  <pre><code>@"&lt;(?&lt;Tag>\w+)[^>)]*>.*?&lt;/\k&lt;Tag>>"</code></pre>
  
  <p>Reality is quite different and all special characters are escaped, so tag looks like: <code>&amp;lt;gallery src=sss&amp;gt;xxx&amp;lt;/gallery&amp;gt;</code>. My problem is to match this king of tags. So far I have this expression:
  <code>@"\&amp;lt\;(?&lt;Tag&gt;\w+)[^\&amp;)]*\&amp;gt\;.*?\&amp;lt\;/\k&lt;Tag&gt;\&amp;gt\;"</code>. It matches tags with no attributes, but not the one mentioned above. What am I missing?</p>
  
  <p>Second issue is matching <code>{| |}</code> tags, because they can be nested. Can you help me with this as well? This expression doesn't do the job: <code>@"\{\|(?:[^\|\}]|\{\|[^\|\}]*\|\})*\|\}"</code></p>
  
  <p><strong>Edit</strong>: To clarify second issue. I have to match strings that starts with opening tag <code>{|</code> then goes some text and ends with <code>|}</code> tags. This structure can be nested, so this: <code>{| xxx {| yyy |} xxx |}</code> is allowed. I don't know maximum nesting level unfortunately, but lets say that 1 should suit most cases.</p>
  
  <hr>
  
  <p><strong>Edit 2</strong>: This expressions works for my 1st issue <code>@"\&amp;lt\;(?&lt;Tag&gt;\w+).*?\&amp;lt\;/\k&lt;Tag&gt;\&amp;gt\;"</code>. I have noticed that it fails if there's a new line mark between opening and closing tags.</p>
  
  <p><strong>Edit 3</strong>: This do the job with second issue: <code>@"\{\|(?&gt;(?!\{\||\|\}).|\{\|(?&lt;N&gt;)|\|\}(?&lt;-N&gt;))*(?(N)(?!))\|\}"</code></p>