This works for me:
C:\Users\Name>echo Hello \hl{my math $\frac{1}{2}$} world | sed "s-\\\hl{\(.*\)}-\\1-"
Hello my math $\frac{1}{2}$ world
This is some version of sed on Windows, more specifically:
C:\Users\Name>sed --version
GNU sed version 4.2.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-gnu-utils@gnu.org>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
But in general, this will not do: It just catches the final bracket of the expression, so multiple \hl{...} (or even other commands after that) might break it. So your example expression, for which my code works, does not represent all the use cases you may want to use it for.
This reminds me a lot of this question. What you want to do is find a matching curly bracket for \hl{; but even assuming that your code parses correctly, meaning that you never have an extra opening or closing bracket anywhere, inside or outside of \hl{...}, regular expressions seem to be incapable of achieving this without recursion, which I am not sure sed supports.
\renewcommand\hl[1]{#1}? – David Carlisle Mar 08 '16 at 20:03Hello \hl{my math $\frac{1}{2}$} world and \hl{my math $\frac{1}{2}$} universe and \whatnotelse, that should be clear from the question, shouldn't it? – bers Mar 08 '16 at 20:14\renewcommand[1]{#1}or\renewcommand*{\hl}{}? Does it make any difference? – n.r. Mar 09 '16 at 07:31*you will get an error if there is a paragraph break (blank line) in the argument, i see no need for such checks in such a comand created by editing a working document. – David Carlisle Mar 09 '16 at 07:41[1]in your version? Why do we need that? Is it to preserve structure or something? – n.r. Mar 09 '16 at 07:45