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

Martin Wilhelm Leidig listwatch at moss.in-berlin.de
Fri Apr 25 06:09:40 EDT 2014


Am 2014-04-25 um 02:41 schrieb Michael Welsh:
> On 25/04/2014, at 1238, Herbert Schulz <herbs at wideopenwest.com> wrote:
>> Find: f\((.*)\)
> 
> This will break on lines such as
> let f(x) be something and g(y) be something else.
> 
> It will match "x) be something and g(y". You need the ? to tell the search to stop after finding the next ), not the last one in the line.


So you need a match for all but ")", e. g.
---
f\(([^\)]*)\)
---
or even giving only the characters one expects inside (…), e. g., "a" to "z":
---
f\(([a-z]*)\)
---

Another way might be to use nongreedy matching, e. g.
---
f\((.*?)\)
---
but that could lead to a lot of backtracking in the process, depending on which type of RE engine is used.  I even don’t know if this is implemented in OgreKit.

See Jeffrey E. F. Friedl’s «Mastering Reglar Expressions» for in-depth information on that.


… mit freundlichem Gruß aus Ladenburg:

-Moss-
-- 
Martin Wilhelm Leidig, SatzTeXnik -- Dante e.V. #1580






More information about the MacOSX-TeX mailing list