Note that there are some explanatory texts on larger screens.

plurals
  1. POstring searching with returning matched line in python
    primarykey
    data
    text
    <p>I am quite new in python.I want to match string in some lines of a file.Let's say, I have string:</p> <pre><code>british 7 German 8 France 90 </code></pre> <p>And I have some lines in a file as like:</p> <pre><code>&lt;s id="69-7"&gt;...Meanwhile is the studio 7 album by British pop band 10cc.&lt;/s&gt; &lt;s id="15-8"&gt;...And Then There Were Three... is the ninth studio album by the german band Genesis 8 and was released in 1978.&lt;/s&gt; &lt;s id="1990-2"&gt;Magnum Nitro Express is a France centerfire fire rifle cartridge 90.&lt;/s&gt; </code></pre> <p>I want to get output as like:</p> <pre><code>&lt;s id="69-7"&gt;...Meanwhile is the studio &lt;w2&gt;7&lt;/w2&gt; album by &lt;w1&gt;British&lt;/w1&gt; pop band 10cc.&lt;/s&gt; &lt;s id="15-8"&gt;...And Then There Were Three... is the ninth studio album by the &lt;w1&gt;german&lt;/w1&gt; band Genesis &lt;w2&gt;8&lt;/w2&gt; and was released in 1978.&lt;/s&gt; &lt;s id="1990-2"&gt;Magnum Nitro Express is a &lt;w1&gt;France&lt;/w1&gt; centerfire fire rifle cartridge &lt;w2&gt;90&lt;/w2&gt;.&lt;/s&gt; </code></pre> <p>I tried with the following code:</p> <pre><code>for i in file: if left in i and right in i: line = i.replace(left, '&lt;w1&gt;' + left + '&lt;/w1&gt;') lineR = line.replace(right, '&lt;w2&gt;' + right + '&lt;/w2&gt;') text = text + lineR + "\n" continue return text </code></pre> <p>But, it also match string from id.eg.</p> <pre><code>&lt;s id="69-&lt;w2&gt;7&lt;/w2&gt;"&gt;...Meanwhile is the studio &lt;w2&gt;7&lt;/w2&gt; album by &lt;w1&gt;British&lt;/w1&gt; pop band 10cc.&lt;/s&gt; </code></pre> <p>So, is there any way to search string as words not as character so that I can escape <code>&lt;s id="69-&lt;w2&gt;7&lt;/w2&gt;"&gt;</code> ?</p> <p>Thanks in advance for any kind of help. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload