regular expressions.

Hrvoje Niksic hniksic at xemacs.org
Fri Aug 8 09:12:53 EDT 2008


"Atul." <atulskulkarni at gmail.com> writes:

> the following does not work.
>
> import re
> vowel =
> r'[u"\u093e"u"\u093f"u"\u0940"u"\u0941"u"\u0942"u"\u0943"u"\u0944"u"\u0945"u"\u0946"u"\u0947"u"\u0948"u"\u0949"u"\u094a"u"\u094b"u"\u094c"]'

Unfortunately you cannot embed arbitrary Python string constants
(u"...") in regular expressions.  What does work is something like:

>>> vowel = u'[\u093e\u093f\u0940\u0941\u0942\u0943\u0944\u0945\u0946\u0947\u0948\u0949\u094a\u094b\u094c]'
>>> re.findall(vowel, u"\u092f\u093e\u0902\u091a\u094d\u092f\u093e")
[u'\u093e', u'\u093e']



More information about the Python-list mailing list