`/[a-zA-Z_]+\d*/` won't match identifiers with numbers in the middle - which are totally valid in ruby. For that, I'd just use @rafaelfranca's regex with a minor improvement: `/[a-zA-Z_]\w*/`. It is more generic, we're basically saying: match a word character, except numbers, then match any amount of word characters (letters, digits or underscore).