Skip to content

Instantly share code, notes, and snippets.

@davidroberts63
Created July 12, 2016 15:32
Show Gist options
  • Save davidroberts63/c022db3856e5aad57cc430fdd0ab2753 to your computer and use it in GitHub Desktop.
Save davidroberts63/c022db3856e5aad57cc430fdd0ab2753 to your computer and use it in GitHub Desktop.
SecondToLastIndexOf
Console.WriteLine("abedef".LastIndexOf("e","abedef".LastIndexOf("e")-1));
// --> 2
// Yes, a bit dirty, but if you use a regex then you'll have two problems.
@davidroberts63
Copy link
Author

You want a regex? You may already have it but I've used this in our build process.

(?'major'\d+).(?'minor'\d+).(?'patch'\d+)

@MJRichardson
Copy link

Unfortunately, SemVer 2 (inc. pre-release and metadata) makes it quite a bit more complex. For parsing e.g. acme.web.1.2.3-alpha.1.2+build into a package name and version, I ended up with:
(?<packageId>(\w+([_.-]\w+)*?))\.(?<semanticVersion>(\d+(\.\d+){0,3}(-[0-9A-Za-z-]*(\.[0-9A-Za-z-]*)*)?)(\+[0-9A-Za-z-]*)?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment