If you're willing and able to use LuaLaTeX to compile your document, the following solution may (should?) be of interest to you. It defines a Lua function which, if activated, renders subscript and superscript terms with \mathrm if there is no whitespace between the _ and ^ characters and the sub/super-script arguments.
The solution also provides two utility macros, named \SubSupToMathrmOn and \SubSupToMathrmOff, respectively, to activate and deactivate the Lua function. By "activate", I mean "assign the Lua function to LuaTeX's process_input_buffer callback so that it functions as a preprocessor."

If you want to render a subscript or superscript term in upright letters without deactivating the Lua function, just make sure to leave whitespace immediately after the _ and ^ characters.
% !TEX TS-program = lualatex
% see also https://tex.stackexchange.com/a/630382/5001
\documentclass{article}
\usepackage{luacode} % for 'luacode' environment
\begin{luacode}
-- Define the Lua function that does all of the work:
function subsup2mathrm ( s )
s = s:gsub ( "_(%b{})" , "_{\\mathrm%1}" )
s = s:gsub ( "_(%a)" , "_{\\mathrm{%1}}" )
s = s:gsub ( "%^(%b{})" , "^{\\mathrm%1}" )
s = s:gsub ( "%^(%a)" , "^{\\mathrm{%1}}" )
return s
end
\end{luacode}
%% LaTeX utility macros to activate and deactivate the Lua function:
\newcommand\SubSupToMathrmOn{\directlua{luatexbase.add_to_callback (
"process_input_buffer" , subsup2mathrm , "subsup2mathrm" )}}
\newcommand\SubSupToMathrmOff{\directlua{luatexbase.remove_from_callback (
"process_input_buffer" , "subsup2mathrm" )}}
\begin{document}
$u_v^w$ $\mu_{something}^{anything}$ % Lua function isn't activated yet
\medskip
\SubSupToMathrmOn % now activate the Lua function
$u_v^w$ $\mu_{something} ^{anything}$ \quad $u_ v ^ w$
\end{document}
\textfor this, as it inherits the formatting of the surrounding text, and therefore might show up italicized in a theorem statement. You would normally use\textupfor the upright text font or\textitfor the italic text font. Both are in theamstextpackage included as part ofamsmath. – Davislor Jan 29 '22 at 21:56\textis the standard command to get text in math, but here normally you would use\mathrmrather than text but in either case what is your actual problem? – David Carlisle Jan 29 '22 at 23:18