Skip to content

Instantly share code, notes, and snippets.

@jgnagy
Last active August 22, 2016 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgnagy/ece787b05237b9e8051180cfcdfc55e8 to your computer and use it in GitHub Desktop.
Save jgnagy/ece787b05237b9e8051180cfcdfc55e8 to your computer and use it in GitHub Desktop.
tab_count = 0
File.readlines('/path/to/file').each do |line|
# The regexp looks for 1 or more tabs at the beginning of the line as a group.
# We then split the result by character, then get the size of the Array from the split.
# Only do all that if the line matches the regexp in the first place.
tab_count += line.match(/^([\t]+)/)[1].split('').size if line.match /^([\t]+)/
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment