title: MySQL REPLACE : How replace all occurrences of a char in every distinct substring delimited by the same head and tail
body: <p>I have this string:</p>
  
  <pre><code>&lt;p&gt;&lt;span&gt;&lt;b&gt;C10373 - FIAT GROUP AUTOMOBILES/RAMO DI AZIENDA DI KUEHNE + NAGEL&lt;/b&gt;&lt;/span&gt;
  &lt;p&gt;la somma pari a € 400+IVA per l’attività&lt;/p&gt;
  &lt;p&gt;TELE+ A 20.000 LIRE AL MESE &lt;/p&gt;
  &lt;li&gt;a mano o via fax al numero +39.00.0.0.0.00.&lt;/li&gt;
  &lt;p&gt;Il punteggio base sarà incrementato di un &lt;strong&gt;+ &lt;/strong&gt;al ricorrere di ciascuna delle seguenti condizioni:&lt;/p&gt;
  &lt;li&gt;&lt;a href="/aaa/gare/CIGZB81E5568D+RDO1560277+Obblighi+contattuali-signed.pdf" title=""&gt;Obblighi contrattuali&lt;/a&gt;&lt;/li&gt; 
  &lt;li&gt;&lt;a href="/aaa/gare/CIGZB81E5568D+RDO1560277+Obblighi+contattuali-signed.pdf" title=""&gt;Obblighi contrattuali&lt;/a&gt;&lt;/li&gt; 
  &lt;li&gt;&lt;a href="/aaa/gare/CIGZB81E5568D+RDO_1560277Lettera_Invito.pdf" title=""&gt;Lettera di invito&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="/aaa/gare/CIGZB81E5568D+RDO1560277+Obblighi+contattuali-signed.pdf" title=""&gt;Obblighi contrattuali&lt;/a&gt;&lt;/li&gt; 
  &lt;li&gt;&lt;a href="/aaa/gare/CIGZB81E5568D+RDO1560277+disciplinare+di+gara-signed.pdf" title=""&gt;Disciplinare di gara&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="/aaa/gare/CIGZB81E5568D+determina+di+aggiudicazione+58+2017.pdf" title=""&gt;Determina di aggiudicazione&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>that is a part of the html content of my record.</p>
  
  <p>Now, my problem is that I tried to replace ONLY the '+' in the href tags, so I create in MySQL this script:</p>
  
  <pre><code>set @xxx = replace(
                  @xxx,
                  substr(@xxx,locate('&lt;a href',@xxx)+3,locate('&lt;/a&gt;',@xxx)-locate('&lt;a href',@xxx)),
                  replace(
                      substr(
                              @xxx, 
                              locate('&lt;a href',@xxx)+3,
                              locate('&lt;/a&gt;',@xxx)-locate('&lt;a href',@xxx)
                          ),
                      '+',
                      ' ')
                  );
  </code></pre>
  
  <p>where @xxx is the string in question.
  The head is <code>&lt;a href</code> and the tail is <code>&lt;/a&gt;</code>, and this never change.</p>
  
  <p>But I obtain this result, with a changing only in the substrings that are the same of the first, because the script search only other substrings with the same central part :</p>
  
  <pre><code>&lt;p&gt;&lt;span&gt;&lt;b&gt;C10373 - FIAT GROUP AUTOMOBILES/RAMO DI AZIENDA DI KUEHNE + NAGEL&lt;/b&gt;&lt;/span&gt;
  &lt;p&gt;la somma pari a € 400+IVA per l’attività&lt;/p&gt;
  &lt;p&gt;TELE+ A 20.000 LIRE AL MESE &lt;/p&gt;
  &lt;li&gt;a mano o via fax al numero +39.06.85.82.12.56.&lt;/li&gt;
  &lt;p&gt;Il punteggio base sarà incrementato di un &lt;strong&gt;+ &lt;/strong&gt;al ricorrere di ciascuna delle seguenti condizioni:&lt;/p&gt;
  &lt;li&gt;&lt;a href="/aaa/gare/CIGZB81E5568D RDO1560277 Obblighi contattuali-signed.pdf" title=""&gt;Obblighi contrattuali&lt;/a&gt;&lt;/li&gt; 
  &lt;li&gt;&lt;a href="/aaa/gare/CIGZB81E5568D RDO1560277 Obblighi contattuali-signed.pdf" title=""&gt;Obblighi contrattuali&lt;/a&gt;&lt;/li&gt; 
  &lt;li&gt;&lt;a href="/aaa/gare/CIGZB81E5568D+RDO_1560277Lettera_Invito.pdf" title=""&gt;Lettera di invito&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="/aaa/gare/CIGZB81E5568D RDO1560277 Obblighi contattuali-signed.pdf" title=""&gt;Obblighi contrattuali&lt;/a&gt;&lt;/li&gt; 
  &lt;li&gt;&lt;a href="/aaa/gare/CIGZB81E5568D+RDO1560277+disciplinare+di+gara-signed.pdf" title=""&gt;Disciplinare di gara&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="/aaa/gare/CIGZB81E5568D+determina+di+aggiudicazione+58+2017.pdf" title=""&gt;Determina di aggiudicazione&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>I must replace all the '+' in the href tags WITHOUT replacing the '+' in the other places, like in '€ 400+IVA' or in 'al numero +39.00.0.0.0.00.' .</p>
  
  <p>Thank you for the help in advance, I hope the question is not so cryptic ^^ .</p>