擅长:python、mysql、java
<p>通过<code>re.sub</code>函数。你知道吗</p>
<pre><code>>>> lines= ['<title>The query complexity of estimating weighted averages.</title>', '<title>New bounds for the query complexity of an algorithm that learns DFAs with correction and equivalence queries.</title>', '<title>A general procedure to check conjunctive query containment.</title>']
>>> words=['a','is','and','there','here']
>>> [re.sub(r'</?title>|\b(?:'+'|'.join(words)+r')\b', r'', line) for line in lines]
['The query complexity of estimating weighted averages.', 'New bounds for the query complexity of an algorithm that learns DFAs with correction equivalence queries.', 'A general procedure to check conjunctive query containment.']
</code></pre>
<p>单词前后的<code>\b</code>有助于精确匹配单词。<code>\b</code>称为单词边界,匹配单词字符和非单词字符。你知道吗</p>