title: String Replacement and Matching in Python 2
body: <p>I have user posts that I would like to match up with a predetermined list of patterns(see example). If the post matches a pattern, I would like to write the post and the pattern to a file. What is the best way to do this? So far I've only thought of brute forcing it with 4 for loops and then doing some comparisons. I already have the lists of all the data I need, below are just some very simple examples to give you an idea of what I am looking for.</p>
  
  <hr>
  
  <p><strong>Example</strong></p>
  
  <p><strong>Posts:</strong></p>
  
  <pre><code>posts =['When I ate at McDonald\'s, I felt sick.',
  'I like eating at Burger King.',
  'Wendy\'s made me feel happy.']
  </code></pre>
  
  <p><strong>Pattern:</strong></p>
  
  <pre><code>patterns = ['When I ate at [RESTAURANT]',
  'I like eating at [RESTAURANT]',
  '[RESTAURANT] made me feel [FEELING]',
  'I felt [FEELING]']
  </code></pre>
  
  <p><strong>Lists:</strong></p>
  
  <pre><code>restaurant_names = ['McDonald\'s', 'Burger King', 'Wendy\'s']
  
  feelings = ['happy', 'sick', 'tired']
  </code></pre>
  
  <p><strong>OutputFile:</strong></p>
  
  <p>When I ate at <code>[RESTAURANT]</code>, When I ate at McDonald's, I felt sick.</p>
  
  <p>I felt <code>[FEELING]</code>, When I ate at McDonald's, I felt sick.</p>
  
  <p><code>[RESTAURANT]</code> made me feel <code>[FEELING]</code>, Wendy's made me feel happy.</p>
  
  <p>I like eating at <code>[RESTAURANT]</code>, I like eating at Burger King.</p>
  
  <hr>
  
  <p>-Sorry for the formatting, but this is my first post on stackoverflow after lurking for a while. Thanks in advance for the help!</p>