Skip to content

Instantly share code, notes, and snippets.

@Capncavedan
Created March 23, 2012 14:06
Show Gist options
  • Save Capncavedan/2170952 to your computer and use it in GitHub Desktop.
Save Capncavedan/2170952 to your computer and use it in GitHub Desktop.
Output set of numbers as ranges
# courtesy of http://codepad.org/tBON208e
$_ = "1,2,3,8,9,12,15,17,18,19,20,21,22,23";
s/(?<!\d)(\d+)(?:,((??{$++1})))+(?!\d)/$1-$+/g;
print;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment