[OS X TeX] Regular expressions

André Bellaïche abellaic at math.jussieu.fr
Sat May 12 12:34:23 CEST 2007


Le 12 mai 07 à 12:03, Maarten Sneep a écrit :

> On May 12, 2007, at 10:58, André Bellaïche wrote:
>
>> With the OgreKit search panel from TeXShop, we can search in the  
>> text for regular expressions.
>>
>> But I could not find what is the good syntax to search for  
>> expressions involving a macro, such as \index{*} (where * stands  
>> for any character string).
>>
>> Can somebody|anybody give me a hand ?
>
> Install TextWrangler, and read the Grep reference in its help. It  
> is the best introduction to regular expression searching I've come  
> across, using the PCRE syntax (recommended, most people will assume  
> you use this variant).
>
>> P.S. The regular expression search does not seem to work very  
>> well : when you search for 'cla*', you get not only  
>> 'documentclass...', but also 'cleardoublepage' or 'clos',  
>> 'cloche'. The 'a' is not seen.
>
> That is because the regular expression actually means something  
> different:
>
> Most characters just mean themselves. * means repeat the previous  
> character zero or more times effectively cancelling the a in your  
> case). + means repeat one or more times, ? means zero of once. The  
> period (.) stands for any character. So "cla.*" should be closer to  
> what you need, altough that will select until the end of the line.

Thanks. So when you type the Unix command   'rm a*'   in Unix to  
remove all the files whose the name begins with an 'a', your are not  
using regular expressions, but something quite different.

>
> The subject of regular expressions is rich and vast, so more direct  
> questions will give more direct answers. As for your first question:
>
> search for: \\index{(.+?)}
> and then you can use \1 to insert the index-term in the replacement  
> pattern. See the TextWrangler help for an explanation why this  
> actually works. The question mark ensures that the shortest match  
> is used. Nested {{}} pairs are still an issue. Be carefull, regular  
> expressions are a form of programming, and can get complicated very  
> quickly.
>
> Maarten
> ------------------------- Helpful Info -------------------------
> Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
> TeX FAQ: http://www.tex.ac.uk/faq
> List Archive: http://tug.org/pipermail/macostex-archives/
> List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/
>
>
>
>


------------------------- Helpful Info -------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/





More information about the macostex-archives mailing list