Python 3 Regex and Unicode Emotes
<p>Using Python 3, a simple script like the following should run as intended, but appears to choke on unicode emote strings:</p>

<pre><code>import re

phrase = "(â¯Â°â¡Â°)â¯ ï¸µ â»ââ»"
pattern = r'\b{0}\b'.format(phrase)

text = "The quick brown fox got tired of jumping over dogs and flipped a table: (â¯Â°â¡Â°)â¯ ï¸µ â»ââ»"

if re.search(pattern, text, re.IGNORECASE) != None:
    print("Matched!")
</code></pre>

<p>If I substitute the word "fox" for the contents of the phrase variable, the pattern does indeed match. I've been puzzled as to why it doesn't like this particular string though, and my expeditions into the manual and Stack Overflow haven't illuminated the issue. From all I can tell, Python 3 should handle this without issue.</p>

<p>Am I missing something painfully obvious?</p>

<p>Edit: Also, dropping the boundaries (\b) doesn't affect the ability to match the string either.</p>

<pre><code>(â¯Â°â¡Â°)â¯ ï¸µ â»ââ»
</code></pre>

<p>This expression has brackets in them, you need to escape them. Otherwise they are interpreted as group.</p>

<pre><code>In [24]: re.search(r'\(â¯Â°â¡Â°\)â¯ ï¸µ â»ââ»', text, re.IGNORECASE)
Out[24]: &lt;_sre.SRE_Match object; span=(72, 85), match='(â¯Â°â¡Â°)â¯ ï¸µ â»ââ»'&gt;

In [25]: re.findall(r'\(â¯Â°â¡Â°\)â¯ ï¸µ â»ââ»', text, re.IGNORECASE)
Out[25]: ['(â¯Â°â¡Â°)â¯ ï¸µ â»ââ»']
</code></pre>

<p><a href="https://docs.python.org/3/library/re.html#re.escape" rel="nofollow">Escape the regex string</a> properly and change your code to:</p>

<pre><code>import re

phrase = "(â¯Â°â¡Â°)â¯ ï¸µ â»ââ»"
pattern = re.escape(phrase)

text = "The quick brown fox got tired of jumping over dogs and flipped a table: (â¯Â°â¡Â°)â¯ ï¸µ â»ââ»"

if re.search(pattern, text, re.IGNORECASE) != None:
    print("Matched!")
</code></pre>

<p>And then it will work as expected:</p>

<pre><code>$ python3 a.py
Matched!
</code></pre>

python regex python-3.x unicode