Reputation: 2589
I know from this question that, nothing to repeat
in a regex expression, is a known bug of python.
But I must compile this unicode expression
re.compile(u'\U0000002A \U000020E3')
as a unique character. This is an emoticon and is a unique character. Python understand this string as u'* \\u20e3'
and rise me 'nothing to repeat' error.
I am looking around but I can't find any solution. Does exist any work around?
Upvotes: 0
Views: 1897
Reputation: 8066
You need to use re.escape (as shown in "Thomas Orozco" answer) But use it only on the part that is dynamic such as:
print re.findall( u"cool\s*%s" % re.escape(u'\U0000002A \U000020E3'),
u"cool * \U000020E3 crazy")
Upvotes: 0
Reputation: 55293
This has little to do with the question you linked. You're not running into a bug. Your regex simply has a special character (a *
) that you haven't escaped.
Simply escape the string before compiling it into a regex:
re.compile(re.escape(u'\U0000002A \U000020E3'))
Now, I'm a little unsure as to why you're representing *
as \U0000002A
— perhaps you could clarify what your intent is here?
Upvotes: 6