Python regex replacing \u2022
<p>This is my string:</p>

<pre><code>raw_list = u'Software Engineer with a huge passion for new and innovative products. Experienced gained from working in both big and fast-growing start-ups.  Specialties \u2022 Languages and Frameworks: JavaScript (Nodejs, React), Android, Ruby on Rails 4, iOS (Swift) \u2022 Databases: Mongodb, Postgresql, MySQL, Redis \u2022 Testing Frameworks: Mocha, Rspec xxxx Others: Sphinx, MemCached, Chef.'
</code></pre>

<p>I'm trying to replace the <code>\u2022</code> with just a space.</p>

<pre><code>x=re.sub(r'\u2022', ' ', raw_list)
</code></pre>

<p>But it's not working. What am I doing wrong?</p>

<p>Unless you use a <em>Unicode</em> string literal, the <code>\uhhhh</code> escape sequence has no meaning. Not to Python, and not to the <code>re</code> module. Add the <code>u</code> prefix:</p>

<pre><code>re.sub(ur'\u2022', ' ', raw_list)
</code></pre>

<p>Note the <code>ur</code> there; that's a raw unicode string literal; this still interprets <code>\uhhhh</code> unicode escape sequences (but is otherwise identical to the standard raw string literal mode). The <code>re</code> module doesn't support such escape sequences itself (but it does support most other Python string escape sequences).</p>

<p>Not that you need to use a regular expression here, a simple <a href="https://docs.python.org/2/library/stdtypes.html#str.replace" rel="nofollow"><code>unicode.replace()</code></a> would suffice:</p>

<pre><code>raw_list.replace(u'\u2022', u' ')
</code></pre>

<p>or you can use <a href="https://docs.python.org/2/library/stdtypes.html#str.translate" rel="nofollow"><code>unicode.translate()</code></a>:</p>

<pre><code>raw_list.translate({0x2022: u' '})
</code></pre>

python regex