result = subject.gsub(/\A[\d_\W]+|[\d_\W]+\Z/, '')
will remove non-letters from the beginning and end of the line.
\A and \Z bind the regular expression at the beginning / end of the line ( ^ / $ will also match after / before the new line, which is probably not what you want - but it may not matter in this case);
[\d_\W]+ matches one or more digits, an underscore, or anything else that is not an alphanumeric character, leaving only letters.
| is an interleave operator.
source share