0

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

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

Comments

0

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,">")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.