<p>Maybe you should try <a href="https://github.com/vi3k6i5/flashtext" rel="noreferrer">flashtext</a>.<br>
According to the author, it is much more faster than Regex.<br>
<a href="https://i.stack.imgur.com/nMfoJ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nMfoJ.png" alt="enter image description here"></a></p>

<p>The author even published a <a href="https://arxiv.org/abs/1711.00046" rel="noreferrer">paper</a> for this library.  </p>

<p>I've personally tried this library for one of my project, in my opinion its API is quite friendly and usable. </p>

<p>Hope it helps.</p>
Find occurrences of huge list of phrases in text
<p>I'm building a backend and trying to crunch the following problem.</p>

<ul>
<li>The clients submit text to the backend (around <code>2000</code> characters on average)</li>
<li>Backend endpoint that receives the request has to apply phrase highlighting to the submitted text</li>
<li><p>There is around <code>80k</code> phrases to match. A phrase is a simple object:</p>

<pre><code>{
    'phrase': 'phrase to match'
    'link': 'link_url'
}
</code></pre></li>
<li><p>After finding all matches of phrases that exist in the text, the backend returns to the client what was matched - basically a map:</p>

<pre><code>range in text -&gt; phrase
</code></pre></li>
</ul>

<p>Most is done. I'm about to tackle coding the phrase matching part. Everything else works smoothly. Since I don't want to reinvent the wheel I tried googling to find a Python library that does the job of efficiently finding phrases (from huge list) in text. However, I couldn't find anything.</p>

<p>I checked out the <a href="https://www.crummy.com/software/BeautifulSoup/" rel="noreferrer">BlueSoup</a> and <a href="https://www.nltk.org/" rel="noreferrer">Natural Language Toolkit</a>. However they don't seem to be doing what I'm looking for.</p>

<p>Do you guys know if there is a library that would be helpful in such task? Seems like a common thing to implement and I don't want to go custom if there is a well established library for that.</p>