You can use a logical OR between FROM and anchor $ :
NAME(.*)(?:FROM|$)
See demo https://regex101.com/r/rR3gA0/1
In this case, after the name, it will match FROM or the end of the line. But in your regular expression, since you make FROM optional in the first case, it will match the rest of the line after the name.
If you want to use a more general regular expression, you better create your regular expression based on your name form forms, for example, if you are sure that your names are created from 2 words, you can use the following regular expression:
NAME\s(\w+\s\w+)
Demo https://regex101.com/r/kV2eB9/2
source share