I only have shallow knowledge of Ruby, and would like to check this is the best way to create a text file by reading items from another file through a regex:
meat will be the contents of the entire file. If input.gpx is small, then it will be fine. Otherwise, you will want to process either by lines or by blocks.
The ^ and $ characters mean “start” and “end” of the line, so they only match full lines consisting of one “word”. ^[a-zA-Z]S is similar, only the asterisk () means “no or any number of” the preceding character/group. The S is just an S and matches exactly one S.