concatenate next to string if string found
<p>I'm trying to search through my strings then concatenate the string.</p>

<pre><code>string =    ' &lt;html&gt;&lt;body&gt;&lt;svg style="background: #40484b;" version="1.1" viewbox="0 0 400 150" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
    &lt;defs&gt;
    &lt;!-- if you use the same shape multiple times, you put the reference here and reference it with &lt;use&gt; --&gt;
    &lt;rect height="100" id="path-1" width="100" x="25" y="25"&gt;&lt;/rect&gt;
    &lt;rect height="100" id="path-3" width="100" x="150" y="25"&gt;&lt;/rect&gt;
    &lt;rect height="100" id="path-5" width="100" x="275" y="25"&gt;&lt;/rect&gt;
    &lt;!-- gradient --&gt;
    &lt;lineargradient id="gradient" x1="50%" x2="50%" y1="0%" y2="100%"&gt;
    &lt;stop offset="0%" stop-color="#FF8D77"&gt;&lt;/stop&gt;
    &lt;stop offset="50%" stop-color="#FFBDB1"&gt;&lt;/stop&gt;
    &lt;stop offset="100%" stop-color="#F4E3F6"&gt;&lt;/stop&gt;
    &lt;/lineargradient&gt;
    &lt;!-- clip-path --&gt;
    &lt;clippath id="clip"&gt;
    &lt;circle cx="325" cy="75" r="50"&gt;&lt;/circle&gt;
    &lt;/clippath&gt;
    &lt;!-- filter --&gt;
    &lt;/defs&gt;&gt;
    &lt;g fill-rule="evenodd"&gt;
    &lt;use fill="#FF8D77" fill-opacity="0.5" filter="url(#glow)" xlink:href="#path-1"&gt;&lt;/use&gt;
    &lt;use fill="url(#gradient)" xlink:href="#path-3"&gt;&lt;/use&gt;
    &lt;use clip-path="url(#clip)" fill="#FF8D77" xlink:href="#path-5"&gt;&lt;/use&gt;
    &lt;/g&gt;
    &lt;/svg&gt;
    &lt;/body&gt;&lt;/html&gt;'
</code></pre>

<p>That's how my string looks like. 
So far this is what I have</p>

<pre><code>    string_list = string
    if "&lt;defs&gt;" in string:
        ###I'm trying to concatenate strings after &lt;defs&gt; like &lt;defs&gt; string string
</code></pre>

<p>Also, I'd like to keep appending strings instead of replacing. Like If I have a user type in something; it keeps adding strings after defs instead of replacing what I already have.</p>

<p>The output I'm expecting would be something like this, I added "concatenated string1" and "concatenated string2". I'm trying to add strings next to "defs" from my string list overall.</p>

<p>Also what I meant by keep adding strings instead of replace is for instance.
I have a 
- first user type in string "concatenate1" 
- Second user type in string "concatenate2"
I want to add both concatenate 1 + contatenate 2 next to my defs tag.</p>

<pre><code>&lt;html&gt;&lt;body&gt;&lt;svg style="background: #40484b;" version="1.1" viewbox="0 0 400 150" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
&lt;defs&gt; &lt;concatenated string1&gt; &lt;concatenated string2&gt;
&lt;!-- if you use the same shape multiple times, you put the reference here and reference it with &lt;use&gt; --&gt;
&lt;rect height="100" id="path-1" width="100" x="25" y="25"&gt;&lt;/rect&gt;
&lt;rect height="100" id="path-3" width="100" x="150" y="25"&gt;&lt;/rect&gt;
&lt;rect height="100" id="path-5" width="100" x="275" y="25"&gt;&lt;/rect&gt;
&lt;!-- gradient --&gt;
&lt;lineargradient id="gradient" x1="50%" x2="50%" y1="0%" y2="100%"&gt;
&lt;stop offset="0%" stop-color="#FF8D77"&gt;&lt;/stop&gt;
&lt;stop offset="50%" stop-color="#FFBDB1"&gt;&lt;/stop&gt;
&lt;stop offset="100%" stop-color="#F4E3F6"&gt;&lt;/stop&gt;
&lt;/lineargradient&gt;
&lt;!-- clip-path --&gt;
&lt;clippath id="clip"&gt;
&lt;circle cx="325" cy="75" r="50"&gt;&lt;/circle&gt;
&lt;/clippath&gt;
&lt;!-- filter --&gt;
&lt;/defs&gt;&gt;
&lt;g fill-rule="evenodd"&gt;
&lt;use fill="#FF8D77" fill-opacity="0.5" filter="url(#glow)" xlink:href="#path-1"&gt;&lt;/use&gt;
&lt;use fill="url(#gradient)" xlink:href="#path-3"&gt;&lt;/use&gt;
&lt;use clip-path="url(#clip)" fill="#FF8D77" xlink:href="#path-5"&gt;&lt;/use&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/body&gt;&lt;/html&gt;
</code></pre>

<p>For a string with multiple lines you should use triple single quotes or triple double quotes. And instead of "if" statement you better use a "for" loop.</p>

python string parsing concatenation