Skip to content

Commit

Permalink
Make regular expression object global wide.
Browse files Browse the repository at this point in the history
  • Loading branch information
kxepal committed Feb 8, 2012
1 parent 4405995 commit a0c9a06
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions semver.py
Expand Up @@ -2,17 +2,17 @@

import re

_REGEX = re.compile("^([0-9]+)" # major
"\.([0-9]+)" # minor
"\.([0-9]+)" # patch
"(\-[0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?" # pre-release
"(\+[0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?$") # build

def parse(version):
"""
Parse version to major, minor, patch, pre-release, build parts.
"""
regex = re.compile(r"^([0-9]+)" # major
+ r"\.([0-9]+)" # minor
+ r"\.([0-9]+)" # patch
+ r"(\-[0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?" # pre-release
+ r"(\+[0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?$") # build
match = regex.match(version)
match = _REGEX.match(version)
if match is None:
raise ValueError('%s is not valid SemVer string' % version)

Expand Down

0 comments on commit a0c9a06

Please sign in to comment.