See the manual. Without the -E flag, grep accepts "base" regular expressions. In this case, most metacharacters lose their special meaning if you do not escape them. So that
grep -nr "STRINGONE_\w\+_\w\+_STRINGTWO"
or
grep -nrE "STRINGONE_\w+_\w+_STRINGTWO"
Or, since you only need uppercase letters:
grep -nr "STRINGONE_[AZ]\+_[AZ]\+_STRINGTWO" grep -nrE "STRINGONE_[AZ]+_[AZ]+_STRINGTWO"
Otherwise, strings with three or more components in the middle will also be accepted.
source share