I'm trying to strip prefixes from a SemVer, i.e, making 1.2.3-prefix.42
into 1.2.3
.
I'm using this RegEx found in https://github.com/mojombo/semver/issues/32#issuecomment-7663411:
^(\d+\.\d+\.\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?
When using Ruby's gsub
method, it works:
puts '1.2.3-alpha.4'.gsub(/^(\d+\.\d+\.\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/, '\1')
# => 1.2.3
But when using sed
form the terminal it doesn't:
$ echo '1.2.3-alpha.4' | sed -e 's/^(\d+\.\d+\.\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/\1/g'
$ 1.2.3-alpha.4
What am I missing?
I'm using zsh on Mac OS X.
Thanks