Regular Expression to select everything before and up to a particular text
After executing the below regex, your answer is in the first capture.
/^(.*?)\.txt/
You could just do ...
(.*?)\.txt
tested here..
This matches everything up to ".txt" (without including it):
^.*(?=(\.txt))