String of alphanumeric characters to a sorted list of comma-separated ranges
Ruby, 87-16=71

EDIT:  Had to add some characters so that two-character ranges are displayed correctly.  Also using ?[ instead of ?Z to fix a bug with ranges ending in Z.

$&gt;&lt;&lt;[*?0..?[].join.gsub(/[^ABC321STPpJqZZr0]/i,$/).gsub(/\B.+\B/,?-).scan(/.-.|./)*', '


You can see the Ideone run here.