title: TSQL search exact match into a string
body: <p>I stumbling on an issue with string parsing; what I'm trying to achieve is substitute a marker string with a value but the string match needs to be perfect.</p>
  
  <p>Keep in mind that before the compare I split the entire string in a table (rowID int, segment nvarchar(max)) wherever i find a space so, a thing like 'The delta_s is §delta_s' will look like:</p>
  
  <blockquote>
    <p>rowID | segment </p>
    
    <p>1    |   the </p>
    
    <p>2    |   deltaT_s </p>
    
    <p>3    |   is </p>
    
    <p>4    |   §deltaT_s</p>
  </blockquote>
  
  <p>After this i cycle each row with my table of "replacements" (idString nvarchar(max), val float); example:</p>
  
  <blockquote>
    <p>Marker string (@segment): '§deltaT_s'</p>
    
    <p>String to replace (@idString): '§deltaT_s'</p>
  </blockquote>
  
  <p>The instruction I am using (since "like" is a lost cause as far I can see):</p>
  
  <pre><code>SELECT STUFF(@segment, PATINDEX('%'+@idString+'[^a-z]%', @segment), LEN(@idString), CAST(@val AS NVARCHAR(MAX)))
  </code></pre>
  
  <p>with @val being the number to substitute taken from the "replacements" table.</p>
  
  <p>Now, in my table of "replacements" i have 2 delta like markers </p>
  
  <blockquote>
    <p>1) §deltaT_s</p>
    
    <p>2) §deltaT</p>
  </blockquote>
  
  <p>My issue is that when the cycle start comparing the segments with the markers and the §deltaT comes up it will substitute the first part of the string in this way </p>
  
  <blockquote>
    <p>'§deltaT_s' -> '10_s'</p>
  </blockquote>
  
  <p>I don't understand what I am doing wrong with the REGEX anyone can give me and hand on this matter?</p>
  
  <p>I am available in case more info are required.</p>
  
  <p>Thank you,
  F.</p>