Python regular expression. Find a sentence in a sentence
<p>I'm trying to find an expression "K others" in a sentence "Chris and 34K others"</p>

<p>I tried with regular expression, but it doesn't work :(</p>

<pre><code>import re


value = "Chris and 34K others"

m = re.search("(.K.others.)", value)

if m:
    print "it is true"
else:
    print "it is not"
</code></pre>

<p>Guessing that you're web-page scraping "<em>you and 34k others liked this on Facebook</em>", and you're wrapping "K others" in a capture group, I'll jump straight to how to get the number:</p>

<pre><code>import re

value = "Chris and 34K others blah blah"

# regex describes
# a leading space, one or more characters (to catch punctuation)
# , and optional space, trailing 'K others' in any capitalisation
m = re.search("\s(\w+?)\s*K others", value, re.IGNORECASE)

if m:
    captured_values = m.groups()
    print "Number of others:", captured_values[0], "K"
else:
    print "it is not"
</code></pre>

<p><a href="https://repl.it/D2ke/4" rel="nofollow">Try this code on repl.it</a></p>

<p>This should also cover uppercase/lowercase K, numbers with commas (1,100K people), spaces between the number and the K, and work if there's text after 'others' or if there isn't.</p>

python regex python-2.7