title: How to compare two sentences by considering the space only in dynamic portion?
body: <p>I need to compare two sentences. First one is defined in a database like below.</p>
  <pre><code>var text1 = &quot;Dear {#dynamic#} {#dynamic#} Welcome to MAX private ltd&quot;
  </code></pre>
  <p>Then the text which comes from customer is given below.</p>
  <pre><code>&quot;var text2 = &quot;Dear joe harry Welcome to MAX private ltd&quot;
  </code></pre>
  <p>Here in place of dynamic there could be any value that customer can substitute and send as an input ( 0- 10) is the character limit for dynamic content.</p>
  <p>I need to compare both the sentences and return the response. Problem here is, we should not consider spaces in the other portion of the sentence except for dynamic part. For example,</p>
  <pre><code>   &quot;var text3 = &quot;Dear joe harry Welcome to MA Xprivatel td&quot;
  </code></pre>
  <p>While comparing text1 with text3 , it should be valid even though we have spaces near the MA Xprivatel td&quot;. But for dynamic portion , if <code>{#dynamic#}{#dynamic#}</code> comes continuously, it can be 20 characters max including spaces. If two
  <code>{#dynamic#} {#dynamic#}</code> with spaces, max character limit can be 21 including spaces.</p>
  <p>My current code is below,</p>
  <pre><code>   text1 = text1.replace(/(^|.)\s($|.)/g, (x, g1, g2) =&gt; (x == &quot;} {&quot; ? &quot;}\\s+{&quot; : g1 + &quot;\\s\*&quot; + g2));
     var separators_regex = /{#dynamic#}|((\s\*))/gi;
     text1= text1.replace(separators_regex, (x, y) =&gt; y ? y : &quot;.{0,10}&quot;); 
     let regex1 = RegExp(&quot;^&quot; + text1+ &quot;$&quot;, &quot;i&quot;);
     if (!regex1.test(text2)) {  // or regex1.test(text3)
          Status = &quot;Fail&quot;  
      }
   
  </code></pre>
  <p>Whatever I try, at some scenario it is failing. The above code is failing for text3.
  Im stuck with these for too long. Can anybody please help me with this?</p>