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>Since there are a lot of emoji <a href="http://apps.timwhitlock.info/emoji/tables/unicode" rel="nofollow">with different unicode values</a>, you have to explicitly specify them in your regex, or if they are with a spesific range you can use a character class. In this case your second simbol is not a standard emoji, it's just a unicode character, but since it's greater than <code>\u263a</code> (the unicode representation of âºï¸) you can put it in a range with <code>\u263a</code>:</p>

<pre><code>In [71]: s = 'blah xzuyguhbc ibcbb bqw 2 extract1  âºï¸ jbjhcb 6 extract2 í ½í¹ bjvcvvv'

In [72]: regex = re.compile(r'\d+(.*?)(?:\u263a|\U0001f645)')

In [74]: regex.findall(s)
Out[74]: [' extract1  ', ' extract2 ']
</code></pre>

<p>Or if you want to match more emojies you can use a character range (here is a good reference which shows you the proper range for different emojies  <a href="http://apps.timwhitlock.info/emoji/tables/unicode" rel="nofollow">http://apps.timwhitlock.info/emoji/tables/unicode</a>):</p>

<pre><code>In [75]: regex = re.compile(r'\d+(.*?)[\u263a-\U0001f645]')

In [76]: regex.findall(s)
Out[76]: [' extract1  ', ' extract2 ']
</code></pre>

<p>Note that in second case you have to make sure that all the characters withn the aforementioned range are emojies that you want.</p>

<p>Here is another example:</p>

<pre><code>In [77]: s = "blah 4 xzuyguhbc í ½í¸º ibcbb bqw 2 extract1  âºï¸ jbjhcb 6 extract2 í ½í¹ bjvcvvv"

In [78]: regex = re.compile(r'\d+(.*?)[\u263a-\U0001f645]')

In [79]: regex.findall(s)
Out[79]: [' xzuyguhbc ', ' extract1  ', ' extract2 ']
</code></pre>

python regex unicode emoji