Thanks for your reponse.
Interestingly, it seems to already sift through math-code,
but the escaping code is somewhat
messy. For example, if you try to replace \hbar with 'word' it
will work, but if you try to replace
'word' with \hbar it will place \\hbar. I bet _that_ cannot be too
hard to fix. Some of the other
escaping is also messy, for example, I wasn't able to get ^{2} to
be replaced with _{2} (even though
this is exactly how it appears in the LyX source). In the longterm,
it would probably be best to have
an ad-hoc search&replace only for math expressions, something
that would be smart enough to
know that ^{2} is equivalent to ^2 and so on, and maybe even tha
t \left( is equivalent to ( (at least
when searching, not when replacing, and of course there are
times when you want this sensitivity...
so it should be switchable).