title: Need simple regex for LaTeX
body: <p>In my LaTeX files, I have literally thousands of occurrences of the following construct:</p>
  
  <pre><code>$\displaystyle{...math goes here...}$
  </code></pre>
  
  <p>I'd like to replace these with</p>
  
  <pre><code>\mymath{...math goes here...}
  </code></pre>
  
  <p>Note that the $'s disappear, but the curly braces remain---if not for the trailing $, this would be a basic find-and-replace.  If only I knew any regex, I'm sure it would handle this with no problem.  What's the regex I need to make this happen?</p>
  
  <p>Many thanks in advance.</p>
  
  <p>Edit: Some issues and questions have arisen, so let me clarify:</p>
  
  <ol>
  <li>Yes, <code>$\displaystyle{ ... }$</code> can occur multiple times on the same line.</li>
  <li>No, nested <code>}$</code>'s (such as <code>$\displaystyle{...{more math}$...}$</code>) cannot occur.  I mean, I suppose it could if you put it in an <code>\mbox</code> or something, but I can't imagine why anyone would ever do that inside a <code>$\displaystlye{}$</code> construct, the purpose of which is to display math inline with text.  At any rate, it's not something I've ever done or am likely to do.</li>
  <li>I tried using the perl suggestion, but while the shell raised no objections, the files remained unaffected.</li>
  <li>I tried using the sed suggestion, but the shell objected to an "unexpected token near `('".  I've never used sed before (and "man sed" was obtuse), but here's what I did: navigated to a directory containing .tex files and typed "<code>sed s/\$\\displaystyle({[^}]+})\$/\\mymath\1/g *.tex</code>".  No luck.  How do I use sed to do what I want?</li>
  </ol>
  
  <p>Again, many many thanks for all offered help.</p>