Skip to content

Instantly share code, notes, and snippets.

@lfgrando
Last active August 31, 2018 15:07
Show Gist options
  • Save lfgrando/36946eeb809bd73d1e68a7718aa8cb8e to your computer and use it in GitHub Desktop.
Save lfgrando/36946eeb809bd73d1e68a7718aa8cb8e to your computer and use it in GitHub Desktop.
Many regex helpers
var content = "{ \"name\": \"Leandro Grando\" }";
// Remove all spaces and new lines from object
var spacelessContent = Regex.Replace(content, @"\s+", string.Empty);
// Minify json string
var minifiedJson = Regex.Replace(content, "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1");
// Negate regex - not tested in c#
var negated = ^((?!gmail.com).)*$
// Between last "." and ".exe".
var between = Regex.Match(Assembly.GetExecutingAssembly().ManifestModule.Name, @"(?<=\.)(\w+?)(?=\.exe$)").Value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment