[OS X TeX] Regular Expression needed...

Alan Munn amunn at gmx.com
Sun Nov 7 20:58:46 EST 2010


On Nov 7, 2010, at 8:30 PM, Herbert Schulz wrote:

>
> On Nov 7, 2010, at 5:33 PM, Gary L. Gray wrote:
>
>> On Nov 7, 2010, at 6:06 PM, Herbert Schulz wrote:
>>
>>> Can someone supply a regex that will find repeated words (e.g.,  
>>> repeated repeated) in a file? This is for use with TeXShop's  
>>> OgreKit Find. It would also be nice to be able to have a replace  
>>> regex to leave only one of the repeats.
>>
>> \b([a-z]+) \1\b
>
> Howdy,
>
> Perfect! and if I put \1 in the Replace: panel it seems to replace  
> it with a single copy. The system will be Cmd-F and set up Find: and  
> Replace: and the Return to find the first duplicate. From then on  
> Replace & Find (Opt-Cmd-G) to replace and find next or Find Next  
> (Cmd-G) to go to the next find without replacing.

Some comments on this.  If you have hard wrapped lines it won't find  
adjacent identical words separated by a line break.  It also fails on  
words separated by tabs or more than one space.  So a better version  
might be:

\b([a-z]+)[ \n\t]+\1\b

(Also, you need to have "Ignore case" set, otherwise you won't catch  
repeated words at the beginnings of sentences).

Alan

-- 
Alan Munn
amunn at gmx.com







More information about the MacOSX-TeX mailing list