# this is *WRONG* from uuid import UUID wrong_uuid = '42d65f9f-e293-5674-8c31-0bfb92d849b0' correct_uuid = '42d65f9f-e293-4674-8c31-0bfb92d849b0' try: UUID(wrong_uuid) print 'success' except: print 'error' # okay your first part was correct :) def validate_uuid(uuid): import re regex = re.compile('^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}\Z', re.I) match = regex.match(uuid) if match: return True else: return False print validate_uuid(wrong_uuid), '(wrong one)' print validate_uuid(correct_uuid), '(correct one)'
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question