title: sql replace all characters between two strings
body: <p>I am trying to figure out a way to update / replace only text between two strings. </p>
  
  <p>For instance I need to be able to update the field and replace only what's in between the following script tags leaving the text before the opening script tag untouched.</p>
  
  <pre><code>I want to keep this string&lt;script type="text/javascript" language="javascript"&gt;********&lt;/script&gt;
  </code></pre>
  
  <p>I suppose REPLACE is not going to work as the text in between the script tags will vary. Is there some type of wildcard? </p>
  
  <pre><code>UPDATE Products_Joined 
  SET TechSpecs = REPLACE (CAST(TechSpecs AS NVARCHAR(MAX)), '&lt;script type="text/javascript" language="javascript"&gt;********&lt;/script&gt;', '&lt;script type="text/javascript" language="javascript"&gt;new text&lt;/script&gt;' )
  </code></pre>
  
  <p>UPDATED: with @Parkyprg answer This works but doesn't replace the closing <code>&lt;/script&gt;</code> tag.
  I end up with this. </p>
  
  <pre><code>I want to keep this string new text&lt;/script&gt;
  </code></pre>
  
  <p>How do we remove the closing script tag as well?  </p>
  
  <pre><code>UPDATE Products_Joined
  SET TechSpecs = REPLACE(CAST(TechSpecs AS NVARCHAR(MAX)), 
  SUBSTRING(CAST(TechSpecs AS NVARCHAR(MAX)),
  CHARINDEX('&lt;script type="text/javascript" language="javascript"&gt;',TechSpecs),
  CHARINDEX('&lt;/script&gt;',CAST(TechSpecs AS NVARCHAR(MAX))) - 
  CHARINDEX('&lt;script type="text/javascript" language="javascript"&gt;',TechSpecs)
  ),' new text') 
  </code></pre>