views:

59

answers:

2

Hi

I am in a situation where I need to match two strings containing HTML.I I can not use exact comparison as the two stings may differ sometimes due to white spaces or something like   etc.

I tried using replace( /[\r\n\t]/g, '' ) this solved my problem with the white spaces.But I am not sure , how can I compare string to succes like

 <span class='foo'> this    is 
                      a 
    test<span>

    with

    <span class='foo'> this &nbsp;&nbsp; is 
                      a 
    test<span>

    or with 

    &gt; span class="foo" &lt; this &nbsp; is 
                      a 
    test &gt;span&lt;

any pointer in this regard will be helpful.

Thanks in advance

+1  A: 

I can think of a 4-steps solution. Do the following on the 2 strings:

  1. Replace any double spaces with one space
  2. Replace new lines with nothing
  3. Convert to lower case
  4. Check equality (using == should be enough)
Makram Saleh
A: 

You will need to do everything you already done plus regexp all you html(html entities) inside text.
To cut html you can use something like this:

stringObject.replace(/&gt;/g,"<")
stringObject.replace(/&lt;/g,">")
Eldar Djafarov