Use of semver recommended regex for tags

I am trying to use the recommended regex for tags:
Is there a suggested regular expression (RegEx) to check a SemVer string?

The one special condition my company requires is that the version tag begins with a v… i.e. v0.1.0.

Here is my config:

  # SEE:
  # SEE:
  # This is that ^^ regex, except it begins with a literal v
  only: ^v(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$

Which doesn’t currently work :/.

I think it’s because I need to add a leading/trailing /. Upon doing so, and entering circleci config validate, I get a config error:

Error: Unknown inline modifier near index 4

Can someone point out what I am doing wrong, or a way I can make this work?

Does CircleCI parsing regex allow named capturing groups, aka ?P?

It depends on how specific and correct you want to be. A regex that perfectly matches the SemVer rules can be fairly long.

What I use for my projects is: /^v\d+\.\d+\.\d+$/. It matches versions that start with a ‘v’ and is three integers separated by a decimal. It doesn’t go into betas and RCs or anything, but works for the simple stuff.

Hi @FelicianoTech thank you for the response!

Yes we currently use a regex very similar. Ours also does not support betas or rc’s, and that’s exactly why I want to use the regex from the semver website here.

If you look at the original post, I was posting about how there is a config error when using the semver regex for named capturing groups. Are you able to provide any input on that?

I was hoping to not have to worry about inventing a new regex, and just instead basically copying + tweaking the semver one.

Hello again!

I discovered two things:

  • The regex may need to begin and end with / (unsure if this is actually true)
  • The config is valid if you remove the named capturing groups, making it:
  # SEE:
  # SEE:
  # This is that ^^ regex, except it begins with a literal v,
  # starts/ends with a `/`and removes all of the named capturing
  # groups
  only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/

So, I am left wondering if CircleCI’s regex implementation supports named capturing groups.