Match unicode emoji in python regex
<p>I need to extract the text between a number and an emoticon in a text</p>

<p>example text:</p>

<pre><code>blah xzuyguhbc ibcbb bqw 2 extract1  âºï¸ jbjhcb 6 extract2 í ½í¹ bjvcvvv
</code></pre>

<p>output:</p>

<pre><code>extract1
extract2
</code></pre>

<p>The regex code that I wrote extracts the text between 2 numbers, I need to change the part where it identifies the unicode emoji characters and extracts text between them.</p>

<pre><code>(?&lt;=[\s][\d])(.*?)(?=[\d])
</code></pre>

<p>Please suggest a python friendly method, and I need it to work with all the emoji's not only the one's given in the example</p>

<p><a href="https://regex101.com/r/uT1fM0/1" rel="nofollow">https://regex101.com/r/uT1fM0/1</a></p>

<p>Here's my stab at the solution. Not sure if it will work in all circumstances. The trick is to convert all unicode emojis into normal text. This could be done by following <a href="http://stackoverflow.com/questions/25707222/print-python-emoji-as-unicode-string">this post</a> Then you can match the emoji just as any normal text. Note that it won't work if the <em>literal</em> strings <code>\u</code> or <code>\U</code> is in your searched text.</p>

<p>Example: Copy your string into a file, let's call it <code>emo</code>. 
In terminal:</p>

<pre><code>Chip chip@ 03:24:33@ ~: cat emo | python stackoverflow.py
blah xzuyguhbc ibcbb bqw 2 extract1  \u263a\ufe0f jbjhcb 6 extract2 \U0001f645 bjvcvvv\n
------------------------
[' extract1  ', ' extract2 ']
</code></pre>

<p>Where <code>stackoverflow.py</code> file is:</p>

<pre><code>import fileinput
a = fileinput.input();
for line in a:
    teststring = unicode(line,'utf-8')
    teststring = teststring.encode('unicode-escape')

import re
print teststring
print "------------------------"
m = re.findall('(?&lt;=[\s][\d])(.*?)(?=\\\\[uU])', teststring)
print m
</code></pre>

python regex unicode emoji