Using Ruby 2.4. I want to create a regular expression by saying match an arbitrary number of spaces followed by a letter that occurs in my array. So I tried this
LETTERS = ["a", "b"]
# => ["a", "b"]
data = ["asdf f", "sdfsdf x"]
# => ["asdf f", "sdfsdf x"]
data.grep(/(^|[[:space:]]+)[#{Regexp.union(LETTERS)}]$/i)
# => ["asdf f", "sdfsdf x"]
but as you can see, despite the fact that neither token ends in a letter in my array, both tokens are getting matched. How do I rewrite my regexp to account for this?