Git Product home page Git Product logo

Comments (6)

serverhorror avatar serverhorror commented on August 22, 2024

And now with corrected tags:

^v?(?P<major>\d+)\.(?P<minor>\d+)\.?P<patchlevel>\d+)~?(?P<special>[a-z]\w+[\d+])?$

from semver.org.

tbull avatar tbull commented on August 22, 2024

So I guess Python doesn't use PCRE, does it?
Anyway, here the expressions from my Java implementation (not yet published):

protected static final Pattern special_pattern = 
    Pattern.compile("[A-Za-z][0-9A-Za-z-]*");
protected static final Pattern semver_pattern =
    Pattern.compile("v?(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?([A-Za-z][0-9A-Za-z-]*)?");

This expression also accepts version numbers with the minor and/or patch number omitted, e.g. "1.2" or "1alpha".

from semver.org.

serverhorror avatar serverhorror commented on August 22, 2024

I think it does. What you get from my regex is a dictionairy (key/value pairs) where the keys are "major", "minor", "patchlevel", "special" so that you can access the different parts by name and not by index from the regex grouping.

from semver.org.

JakeWharton avatar JakeWharton commented on August 22, 2024

@serverhorror your regex doesn't adhere to rule 3 properly. Something like [a-zA-Z][-a-zA-Z0-9]* is better for the body of the 'special' clause.

The rule doesn't explicitly declare it, but it seems odd to allow a trailing dash (-). Perhaps this should be brought up as another issue. This can be included by changing the 'special' clause to ([a-zA-Z][-a-zA-Z0-9]*)(?<!-).

from semver.org.

mojombo avatar mojombo commented on August 22, 2024

I think this is outside the scope of SemVer. The spec should state the requirements clearly enough to easily construct a RegEx, and if it does not then that is a failure of the spec and should be addressed separately.

from semver.org.

krainboltgreene avatar krainboltgreene commented on August 22, 2024

I know this is old, but would it be beneficial to have "examples" enough to that implementation builders have test cases?

from semver.org.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.