The Drupal update system uses a pre-semver approach of version numbering.

Major versions must be in the form of "8.x", as opposed to other semver
ranges or version numbers.
7198
function toDrupalMajorVersion(version) {
    var regex = /^(\d+)\.\d+\.[x\d+]/;
    var match = version.match(regex)
    if (match) {
      return match[1] + '.x';
    }

    return version;
  }
146834
def version_at_least(version_string, major, minor, micro, patch):
    
    parts = re.match(
        r'^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+).*$',
        version_string,
    )
    for ver, gold in zip(parts.group(1, 2, 3, 4), (major, minor, micro, patch)):
        if int(ver) < int(gold):
            return False
        elif int(ver) > int(gold):
            return True
    return True
772349
function compareVersions(fstVer, sndVer) {
    if (semver.lt(fstVer, sndVer)) {
        return 1;
    }
    if (semver.gt(fstVer, sndVer)) {
        return -1;
    }
    return 0;
}
1126715
def get_version(version_tuple):
    """"""
    if version_tuple[3] == FINAL and version_tuple[4] != 0:
        raise Exception(
            'Project version number misconfigured:\n'
            '   version may not be final and have segment number.')

    if version_tuple[3] not in (DEV, FINAL) and version_tuple[4] == 0:
        raise Exception(
            'Project version number misconfigured:\n'
            '   version must have segment number.')

    if version_tuple[3] == DEV:
        segment_num = get_git_changeset()
    else:
        segment_num = str(abs(version_tuple[4]))

    # X.X.X
    sem_ver = ".".join([
        str(abs(int(number)))
        for number in version_tuple[:3]
    ])

    if version_tuple[3] != FINAL:
        if version_tuple[3] in (ALPHA, BETA, RC):
            sem_ver = "%s%s%s" % (sem_ver, version_tuple[3], segment_num)
        elif version_tuple[3] in (DEV, POST):
            sem_ver = "%s%s%s%s" % (
                sem_ver, SEPARATOR, version_tuple[3], segment_num)
        else:
            raise Exception(
                'Project version number misconfigured:\n'
                '   Unrecognized release type')

    return sem_ver
1373935
def version(self, calver: bool = False, pre_release: bool = False) -> str:
        
        # TODO: Optimize
        version = '{}.{}.{}'
        major, minor, patch = self.random.randints(3, 0, 10)

        if calver:
            if minor == 0:
                minor += 1

            if patch == 0:
                patch += 1
            major = self.random.randint(2016, 2018)
            return version.format(major, minor, patch)

        version = '{}.{}.{}'.format(major, minor, patch)

        if pre_release:
            suffixes = ('alpha', 'beta', 'rc')
            suffix = self.random.choice(suffixes)
            number = self.random.randint(1, 11)
            return '{}-{}.{}'.format(version, suffix, number)

        return version
533748
private function validateVersion()
    {
        $this->blacklistCheck($this->version);
        if (!empty($this->version) &&
            (
                str_replace('+', '', filter_var($this->version, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)) !== $this->version ||
                version_compare($this->version, '0.0.1', '>=') === false
            )
        ) {
            throw new Exceptions\VersionException("Invalid version format (`$this->version`). See http://semver.org/ for guidelines. In addition, dev/alpha/beta/rc tags is disallowed. See also " . self::RFC_README);
        }
        $this->version = trim($this->version, '.0');
        return true;
    }
1063130
function(str){
        var versionArray = str.split(",");//replace with regex
        return {
            "raw":str,
            "major":parseInt(versionArray[0].split(" ")[1], 10),
            "minor":parseInt(versionArray[1], 10),
            "revision":parseInt(versionArray[2], 10),
            "revisionStr":versionArray[2]
        };
    }
610836
function normVersion(tag) {
    var parts = new semver.SemVer(tag);
    var prerelease = "";

    if (parts.prerelease && parts.prerelease.length > 0) {
        prerelease = hashPrerelease(parts.prerelease);
    }

    return [
        parts.major,
        parts.minor,
        parts.patch
    ].join('.') + (prerelease? '.'+prerelease : '');
}
1101745
def increment_version(version):
    

    parts = [int(v) for v in version.split('.')]
    parts[-1] += 1
    parts.append('dev0')

    return '.'.join(map(str, parts))
249337
function default_versionCode(version) {
    var nums = version.split('-')[0].split('.');
    var versionCode = 0;
    if (+nums[0]) {
        versionCode += +nums[0] * 10000;
    }
    if (+nums[1]) {
        versionCode += +nums[1] * 100;
    }
    if (+nums[2]) {
        versionCode += +nums[2];
    }
    return versionCode;
}
1279721
def bump_version(v: version.Version, level: str) -> str:
    """"""
    release: List[int] = list(v.release)
    stage: Optional[str]
    pre: Optional[int]
    stage, pre = v.pre if v.pre else (None, None)
    dev: Optional[int] = v.dev
    post: Optional[int] = v.post

    if level in ("major", "minor", "patch"):
        segments = 0
        if level == "major":
            # if the version code is in format of x.0.0, and pre/dev is not empty
            # do not increase the version number
            segments = 1
        elif level == "minor":
            # if the version code is in format of x.x.0, and pre/dev is not empty
            # do not increase the version number
            segments = 2
        elif level == "patch":
            # if the version code is in format of x.x.x, and pre/dev is not empty
            # do not increase the version number
            segments = 3
        if not any(release[segments:]) and (stage is not None or dev is not None):
            pass
        else:
            release[segments - 1] += 1
        release[segments:] = [0] * max(len(release) - segments, 0)
        stage = pre = post = dev = None
    elif level == "alpha":
        if stage is None:
            if dev is None:
                release[-1] += 1
            stage, pre = "a", 1
        elif stage > "a":
            release[-1] += 1
            stage, pre = "a", 1
        elif stage == "a":
            pre += 1
        post = dev = None
    elif level == "beta":
        if stage is None:
            if dev is None:
                release[-1] += 1
            stage, pre = "b", 1
        elif stage > "b":
            release[-1] += 1
            stage, pre = "b", 1
        elif stage == "b":
            pre += 1
        elif stage < "b":
            pre = 1
            stage = "b"
        post = dev = None
    elif level == "post":
        if post is not None:
            post += 1
        else:
            post = 1
        dev = None
    elif level == "dev":
        if dev is not None:
            dev += 1
        else:
            if stage:
                pre += 1
            else:
                release[-1] += 1
            dev = 1

    ver = ".".join(str(i) for i in release)
    if stage is not None:
        ver += f"{stage}{pre}"
    if post is not None:
        ver += f".post{post}"
    if dev is not None:
        ver += f".dev{dev}"

    return ver
236368
def _get_next_version(self, revisions):
        
        versions = [0]
        for v in revisions:
            if v.isdigit():
                versions.append(int(v))
        return six.text_type(sorted(versions)[-1] + 1)
1257303
def bump_minor_version():
    """"""
    version = load_version_as_list()
    print('current version: {}'.format(format_version_string(version)))
    version[-1] += 1
    print('new version: {}'.format(format_version_string(version)))

    contents = "__version__ = '{}'\n".format(format_version_string(version))

    with open(VERSION_PATH, 'w') as wfile:
        wfile.write(contents)
1033102
def next_version
      parse unless parsed?
      (major, minor, patch) = current_version.split(".").collect { |n| n.to_i }
      if !changes[:major].empty?
        major += 1
        patch = minor = 0
      elsif !changes[:minor].empty?
        minor += 1
        patch = 0
      else
        patch += 1
      end
      "%d.%d.%d" % [ major, minor, patch ]
    end
714919
def get_version(version=None):
    """"""
    if version is None:
        version = VERSION
    assert len(version) == 5
    assert version[3] in ('alpha', 'beta', 'rc', 'final')

    # Now build the two parts of the version number:
    # main = X.Y[.Z]
    # sub = .devN - for pre-alpha releases
    #     | {a|b|c}N - for alpha, beta and rc releases

    parts = 2 if version[2] == 0 else 3
    main = '.'.join(str(x) for x in version[:parts])

    sub = ''
    if version[3] == 'alpha' and version[4] == 0:
        # At the toplevel, this would cause an import loop.
        from django.utils.version import get_svn_revision
        svn_revision = get_svn_revision()[4:]
        if svn_revision != 'unknown':
            sub = '.dev%s' % svn_revision

    elif version[3] != 'final':
        mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
        sub = mapping[version[3]] + str(version[4])

    return main + sub
480818
def get_final_version_string(release_mode, semver, commit_count=0):
    """"""
    version_string = ".".join(semver)
    maybe_dev_version_string = version_string
    updates = {}
    if release_mode:
        # in production, we have something like `1.2.3`, as well as a flag e.g. PRODUCTION=True
        updates[Constants.RELEASE_FIELD] = config.RELEASED_VALUE
    else:
        # in dev mode, we have a dev marker e.g. `1.2.3.dev678`
        maybe_dev_version_string = config.DEVMODE_TEMPLATE.format(
            version=version_string, count=commit_count
        )

    # make available all components of the semantic version including the full string
    updates[Constants.VERSION_FIELD] = maybe_dev_version_string
    updates[Constants.VERSION_STRICT_FIELD] = version_string
    return updates
1070039
def sort_versions(versions=(), reverse=False, sep=u'.'):
    
    if versions == []:
        return []

    digits = u'0123456789'

    def toint(x):
        try:
            n = int(x)
        except:
            n = x
        return n
    versions = list(versions)
    new_versions, alpha, sizes = [], set(), set()

    for item in versions:
        it = item.split(sep)
        temp = []
        for i in it:
            x = toint(i)
            if not isinstance(x, int):
                x = u(x)
                middle = x.lstrip(digits).rstrip(digits)
                tail = toint(x.lstrip(digits).replace(middle, u''))
                head = toint(x.rstrip(digits).replace(middle, u''))
                middle = toint(middle)
                res = [head, middle, tail]
                while u'' in res:
                    res.remove(u'')
                for r in res:
                    if is_unicode(r):
                        alpha.add(r)
            else:
                res = [x]
            temp += res
        sizes.add(len(temp))
        new_versions.append(temp)

    # replace letters found by a negative number
    replace_dic = {}
    alpha = sorted(alpha, reverse=True)
    if len(alpha):
        replace_dic = dict(zip(alpha, list(range(-1, -(len(alpha)+1), -1))))

    # Complete with zeros based on longest item and replace alphas with number
    nmax = max(sizes)
    for i in range(len(new_versions)):
        item = []
        for z in new_versions[i]:
            if z in replace_dic:
                item.append(replace_dic[z])
            else:
                item.append(z)

        nzeros = nmax - len(item)
        item += [0]*nzeros
        item += [versions[i]]
        new_versions[i] = item

    new_versions = sorted(new_versions, reverse=reverse)
    return [n[-1] for n in new_versions]