Reputation: 5152
I have unicode strings like
u'0d7a6b6b37682bab6d8eda97cda4bad7'
and
u'Brauers, A.'
I would like to distinguish between two of these. I tried using regex
with \p{Alphabet}
but it does not work with the second example as the second example contains ,
and .
. Can anyone help me with this?
Upvotes: 1
Views: 187
Reputation: 375494
The simplest thing might be to check for non-hex digits:
if re.match(r'[^0-9a-f]', my_string):
# This is a u'Brauers, A.' kind of string
else:
# This is a u'0d7a6b6b37682bab6d8eda97cda4bad7' kind of string
Upvotes: 2
Reputation: 11163
Just check for hex digits?
>>> re.match(r'^[0-9a-f]*$', u'0d7a6b6b37682bab6d8eda97cda4bad7') != None
True
>>> re.match(r'^[0-9a-f]*$', u'Brauers, A.') != None
False
Upvotes: 4