It's commonly said that regular expressions cannot count, which is kind of a loose way of describing a problem more formally discussed in Count parentheses with regular expression. See that for what this means.
Now, with that in mind, note that LaTeX math expressions can include nested sub-equations, which can include further nested sub-equations, and so on. This is analogous to the problem of detecting whether a closing parenthesis closes an inner parenthesized expression (as in (for instance) this example, where the first one does not) or an outer parenthesis. Therefore, regular expressions are not going to be powerful enough to handle the full general case.
If you're willing to do a less-than-complete job, you can construct a regular expression that finds $...$
and $$...$$
. You will need to pay attention to the particular regular expression language available. Python's is essentially the same as Perl's here.
Importantly, these $
-matchers will completely miss \begin{equation} ... \end{equation}
, \begin{eqnarray} ... \end{eqnarray}
, and so on. We've already noted that handling LaTeX expression parsing with a mere regular expression recognizer is inadequate, so if you want to do a good job—while ignoring the complexity of lower-level TeX manipulation of token types, where one can change any individual character's category code —you will want a more general parser. You can then tokenize \begin
, {
, }
, and words, and match up the begin/end pairs. You can also tokenize $
and $$
and match those up. Since parsers can count, in exactly the way that regular expressions can't, you can do a much better job this way.