title: matching stored keywords/phrases in text
body: <p>I have a database table with around 1000 keywords/phrases (one to four words long) - This table changes rarely, so I could extract the data into something more useful (like a regular expression?) - So this is not finding / guessing at keywords based on natural language processing..</p>
  
  <p>I then have a user inputting some text into a form that I'd like to match against my keywords and phrases.</p>
  
  <p>The program would then store a link to each phrase matched next to the text.</p>
  
  <p>So if we ran the algorithm on this question text against a few phrases that are in here, we'd get a result like so:</p>
  
  <pre><code>{"inputting some text" : 1,
   "extract the data" : 1,
   "a phrase not here" : 0}
  </code></pre>
  
  <p>What are my options?</p>
  
  <ol>
  <li>Compile a regular expression</li>
  <li>Some sort of SQL query</li>
  <li>A third way?</li>
  </ol>
  
  <p>Bearing in mind that there's a 1000 possible phrases..</p>
  
  <p>I'm running Django / Python with MySQL.</p>
  
  <p>edit: I'm currently doing this:</p>
  
  <pre><code>&gt;&gt;&gt; text_input = "This is something with first phrase in and third phrase" 
  &gt;&gt;&gt; regex = "first phrase|second phrase|third phrase" 
  &gt;&gt;&gt; p = re.compile(regex, re.I) 
  &gt;&gt;&gt; p.findall(text_input)
  ['first phrase','third phrase']
  </code></pre>