[OS X TeX] Regex to catch more than one line

Alan Munn amunn at gmx.com
Sat Nov 20 11:07:46 EST 2010

On Nov 20, 2010, at 10:13 AM, Frank STENGEL wrote:

> Hello,
> I am trying (and failing) to write a regular expression that catches  
> text (split on more than one line or not) that is between $$'s in  
> order to replace these $$'s by \begin{equation*}...\end{equation*}
> I tried
> \$\$(.*)\$\$

* is greedy, so you don't want to use it to find delimited text. (It  
will incorrectly find "$X$  foo $Y$" instead of two instances of $X$  
and $Y$. You should use the non-greedy version .*? (or .+?)

> as the expression to be found. Alas this does not work if the  
> displayed math is coded using more than one line.

Using the Perl regular expression engine you can use the following:


the (?s) tells the regex interpreter to treat . as truly any character  
(including newlines).

(I don't know which editor you are using; if you're using TeXShop,  
click on the More Options button in the Find window and make sure that  
Perl search syntax is chosen.


Alan Munn
amunn at gmx.com

More information about the MacOSX-TeX mailing list