Regex. How to remove multiple occurence of 'u' if it's befoure some symbol


I have this string:
p = "{u'symbols': [], u'user_mentions': [{u'indices': [0, 9], u'id': 1425561991, u'id_str': u'1425561991', u'name': u'h u2661', u'screen_name': u'oppsli4m'}, {u'indices': [10, 23], u'id': 27260086, u'id_str': u'27260086', u'name': u'Justin Bieber', u'screen_name': u'justinbieber'}], u'hashtags': [], u'urls': []}"
As you can see I have a "Unicode character" in front of every string. So I want to remove every single u if it is in front of '.
I tried :
vals = re.split('u', p)
And some other variations of this expression. But had no luck.
I hope my question is clear, but just in case , the result that I want to get should look something like this:
"{'symbols': [], 'user_mentions': [{'indices': [0,9], 'id': 124......"

asked Sep 13, 2013 in Regular-exp by rajesh
edited Sep 12, 2013
0 votes

1 Answer

0 votes


I guess this is what you are looking for:

import re
print re.sub(r"u('\w)", r"\1", p)


answered Sep 13, 2013 by rajesh
edited Sep 12, 2013