[OS X TeX] Regular expressions with TeXShop

BELLAICHE André andre.bellaiche at imj-prg.fr
Sun Oct 19 18:58:18 EDT 2014


Le 20 oct. 2014 à 00:35, Michael Sharpe <msharpe at ucsd.edu>
 a écrit :

> 
>> On Oct 19, 2014, at 3:10 PM, BELLAICHE André <andre.bellaiche at imj-prg.fr> wrote:
>> 
>> I am lost with regular expressions. Moerover, it seems that they are various dialects of regular expressions depending of the OS or the programming language you use.
>> 
>> But I use TeXShop, and today I would only replace \textcolor{red}{some text} by [some text], including the square brackets.
>> 
>> I have found that in the "find" box, I should type 
>> 
>> \\textcolor{red}{(+)}
>> 
>> and in the "replace" box, I should type
>> 
>> [\1] 
>> 
>> But it doesn't work. 
>> 
>> I get the error message "Invalid regular expression. Target of repeat operator is not specified".
>> 
>> Can somebody help me? Also, where can I find a good introduction to the subject? In what I find on the Internet, they suppose that you know everything about the subject except the thing they are presently describing. Just like a Chinese grammar written in Chinese.
>> 
>> Thanks in advance,
>> 
> 
> I assume you've selected ogrekit for your RFind Panel in TeXShop preferences. If you click on More options in the find panel to set the preferred regex syntax. I use perl style because it is pretty well documented on-line and in manuals. Your search term will work if you change it to
> 
> \\textcolor\{red\}\{(.+)\}
> 
> (You have to escape each term with special meaning, like {, [,],}, and the repeat operator + needs the period before it so it matches any number of characters.) Then [\1] will do the replacement as expected.
> 
> Michael


It worked! Many thanks,

André


More information about the MacOSX-TeX mailing list