I lack experience with regex and I need some help.
I need to extract a git tag. The input string is like this:
6dde3d91f23bff5ab81e91838f19f306b33fe7a8refs/tags/3.4.2
// there is a new line at the end of the string
The part of the string I need is 3.4.2. Here is my code:
var pattern = /.*([0-9]{1}\.{1}[0-9]{1}\.{1}[0-9]{1}).*/ig;
var match = pattern.exec(string);
// match[1] gets what I need
It works, but this regex is ridiculously long, there must be a way to make it shorter. Can somebody help me?
Thanks
You can replace
[0-9]{1}with\das follows:The
$matches the end of the line.Edit: updated based on Rob-W‘s feedback