Skip to content

Instantly share code, notes, and snippets.

@xadn
Created February 27, 2011 20:56
Show Gist options
  • Save xadn/846530 to your computer and use it in GitHub Desktop.
Save xadn/846530 to your computer and use it in GitHub Desktop.
Ruby regex for stripping comments and whitespace
# Remove comments, whitespace, newlines, and returns
# Use line.gsub! to modify the actual line instead of just returning the result
@input = line.gsub(/\t|\s|\n|\r|\/{2}.*$/, '')
# Then, once all of the crap is gone make sure to skip empty lines
if(!@input.empty?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment