title: removing emojis from a string in Python
body: <p>I found this code in Python for removing emojis but it is not working. Can you help with other codes or fix to this? </p>
  
  <p>I have observed all my emjois start with <code>\xf</code> but when I try to search for <code>str.startswith("\xf")</code> I get invalid character error.</p>
  
  <pre><code>emoji_pattern = r'/[x{1F601}-x{1F64F}]/u'
  re.sub(emoji_pattern, '', word)
  </code></pre>
  
  <p>Here's the error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "test.py", line 52, in &lt;module&gt;
      re.sub(emoji_pattern,'',word)
    File "/usr/lib/python2.7/re.py", line 151, in sub
      return _compile(pattern, flags).sub(repl, string, count)
    File "/usr/lib/python2.7/re.py", line 244, in _compile
      raise error, v # invalid expression
  sre_constants.error: bad character range
  </code></pre>
  
  <p>Each of the items in a list can be a word <code>['This', 'dog', '\xf0\x9f\x98\x82', 'https://t.co/5N86jYipOI']</code></p>
  
  <p>UPDATE:
  I used this other code:</p>
  
  <pre><code>emoji_pattern=re.compile(ur" " " [\U0001F600-\U0001F64F] # emoticons \
                                   |\
                                   [\U0001F300-\U0001F5FF] # symbols &amp; pictographs\
                                   |\
                                   [\U0001F680-\U0001F6FF] # transport &amp; map symbols\
                                   |\
                                   [\U0001F1E0-\U0001F1FF] # flags (iOS)\
                            " " ", re.VERBOSE)
  
  emoji_pattern.sub('', word)
  </code></pre>
  
  <p>But this still doesn't remove the emojis and shows them! Any clue why is that?
  <a href="https://i.stack.imgur.com/8xXfy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8xXfy.png" alt="enter image description here"></a></p>