title: Tokenization which works with terms that contain whitespace in Python?
body: <p>My standard approach to tokenize a text using a regex in Python is this:</p>
  
  <pre><code>&gt; text = "Los Angeles is in California"
  &gt; tokens = re.findall(r'\w+', text)
  &gt; tokens
  ['Los','Angeles','is','in','California']
  </code></pre>
  
  <p>A problem arises if I want to find the name <code>Los Angeles</code> in the above text.</p>
  
  <p><strong>What is the best way to find a needle which contains whitespace in a haystack?</strong></p>
  
  <p>I am asking a general question, because the solution should also work for a case like <code>United States of America</code> and for needles which don't contain whitespace.</p>
  
  <p>For example a simple <code>if "Los Angeles" in text</code> (match) would not do, because <code>if "for" in text</code> would also return a match. But I am looking for full words only (match <code>for</code> and not <code>California</code>).</p>