title: Auto Regex Generator - Similarity Between 2 strings c#
body: <p>I am trying to create a regex generator for scrapping purposes, and any guidance is appreciated.</p>
  
  <p>The idea is that we have a big text (html), we select 2 (at least) DOM elements that are always similar (like the first 2 results from google) and than we should generate a regular expression that will scrape (match) this results.</p>
  
  <p>Example:
  Selected element 1 (this will be inputed by a user):</p>
  
  <pre><code>&lt;a onmousedown="return rwt(this,'','','','1','AFQjCNHqQo9TrXtXXM5lDpiCmNQO9xwkhw','','0CGoQFjAA',null,event)" class="l" href="http://www.miniclip.com/"&gt;&lt;em&gt;Games&lt;/em&gt; at Miniclip.com - Play Free Online &lt;em&gt;Games&lt;/em&gt;&lt;/a&gt;
  </code></pre>
  
  <p>Selected element 2 (this will be inputed by a user):</p>
  
  <pre><code>&lt;a onmousedown="return rwt(this,'','','','2','AFQjCNGlNySkvcXMxEUmjCMOJRQPCdqBHQ','','0CHIQFjAB',null,event)" class="l" href="http://www.games.com/"&gt;&lt;em&gt;Games&lt;/em&gt;.com: Play &lt;em&gt;Games&lt;/em&gt; Online - Free &lt;em&gt;Games&lt;/em&gt;, Download &lt;em&gt;Games&lt;/em&gt; &lt;b&gt;...&lt;/b&gt;&lt;/a&gt;
  </code></pre>
  
  <p>HTML text that contains both elements:</p>
  
  <pre><code>&lt;ol id="rso" eid="GcrGT_KHH4f3sgbXmci5Cw"&gt;&lt;!--m--&gt;&lt;li class="g"&gt;&lt;div sig="U8P" bved="0CBUQkQo" pved="0CBQQkgowAA" class="vsc"&gt;&lt;h3 class="r"&gt;&lt;a onmousedown="return rwt(this,'','','','1','AFQjCNHqQo9TrXtXXM5lDpiCmNQO9xwkhw','','0CGoQFjAA',null,event)" class="l" href="http://www.miniclip.com/"&gt;&lt;em&gt;Games&lt;/em&gt; at Miniclip.com - Play Free Online &lt;em&gt;Games&lt;/em&gt;&lt;/a&gt;&lt;/h3&gt;&lt;div class="vspib" aria-label="Detalii rezultat" role="button" tabindex="0"&gt;
  
  &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;!--n--&gt;&lt;/li&gt;&lt;!--m--&gt;&lt;li class="g"&gt;&lt;div sig="fUe" bved="0CBsQkQo" pved="0CBoQkgowAQ" class="vsc"&gt;&lt;h3 class="r"&gt;&lt;a onmousedown="return rwt(this,'','','','2','AFQjCNGlNySkvcXMxEUmjCMOJRQPCdqBHQ','','0CHIQFjAB',null,event)" class="l" href="http://www.games.com/"&gt;&lt;em&gt;Games&lt;/em&gt;.com: Play &lt;em&gt;Games&lt;/em&gt; Online - Free &lt;em&gt;Games&lt;/em&gt;, Download &lt;em&gt;Games&lt;/em&gt; &lt;b&gt;...&lt;/b&gt;&lt;/a&gt;&lt;/h3&gt;&lt;div class="vspib" aria-label="Detalii rezultat" role="button" tabindex="0"&gt;
  </code></pre>
  
  <p>In this case, the good regex would be:</p>
  
  <pre><code>(&lt;h3 class="r"&gt;)(.*?)(&lt;/h3&gt;&lt;div)
  </code></pre>
  
  <p>Not to hard to figure out. The problem appears when <code>&lt;h3 class="r"&gt;</code> appears in another element that is not related to our results. For example if you add:</p>
  
  <pre><code>&lt;h3 class="r"&gt;THIS IS JUST AN EXTRA THING&lt;/h3&gt; 
  </code></pre>
  
  <p>at start of the HTML text, the regex from above would not work.</p>
  
  <p>The new regex would need to be:</p>
  
  <pre><code>(class="vsc"&gt;&lt;h3 class="r"&gt;)(.*?)(&lt;/h3&gt;&lt;div)
  </code></pre>
  
  <p>I know this is not an easy thing to acheieve, but my idea is to find the similarities of the elements (for example take 100 characters before and after the elements and see what are identical for element 1/element 2).</p>
  
  <p>Hope somebody can guide me on what would be the best way to achieve this.</p>
  
  <p>Thanks in advance</p>