[OS X TeX] Search with .* but how to replace?

Alain Schremmer schremmer.alain at gmail.com
Sat Apr 26 18:43:28 CEST 2014


On Apr 24, 2014, at 8:33 PM, Michael Welsh wrote:

> As long as x doesn't contain any (), the following works:
>
> Set search syntax to Perl (click on more options) and escape  
> character to \.
>
> Then search
> f\((.*?)\)
>
> and replace
> g(\1)h(\1)
>
> For a good place to read about this, I suggest the TextWrangler  
> (free from the App Store) help.

On Apr 24, 2014, at 8:38 PM, Herbert Schulz wrote:

> Find: f\((.*)\)
>
> Replace: g(\1)h(\1)
>
> Note: (...) has a special meaning and the text inside the ( and ) is  
> saved. The first set gives rise to \1, the second set \2, etc. To  
> get a standard meaning for ( and ) in the Find part you need to  
> quote them; i.e., place a \ before them, hence \( and \).



I finally got around trying the regex suggestion (with the ?) and  
looking up TextWrangler's help. Neither worked. Both my fault:

(1)	That the regex didn't work is because I botched my "minimal  
example": instead of saying I wanted to replace f(x) by g(x)h(x) (for  
which of course the regex worked) I should have said I wanted to  
replace \f{x} with \g{x}\h{x}. In other words, I am trying to search  
for a command and replace it with two commands (*)

And none of the many variations I tried worked. My most surprising  
failure was (I was ready to insert the \ with a separate search.)

Given \f{x} in the text,
	Search for f{.*?} found it
	Replace with g{\1}h{\1} replaced with g{}h{} instead of with g{x}h{x}


(2)	That the reading suggestion didn't work should go without saying:  
as much as I loved TextWrangler for doing multiple file search and  
replace so transparently, I have a very hard time plunging into the  
middle of its help and make much sense of it.


Grateful---and hopeful---regards
--schremmer

  (*) I need to replace \NewTerm{blah} by \textbf{blah}\index{blah}  
(which is what \NewTerm does) because, occasionally, I need to edit  
to, say, \textbf{blahs}\index{blah} or  \textbf{blahs}\index{blah (to)}.




More information about the macostex-archives mailing list