0

I'm trying to replace something like this:

NSSomeFunction(@"some var", @"another one")

With:

NSSomeOhterFunction(@"some var")

In Xcode. So these are source files... I bet the regular expression will look something like this:

NSSomeFunction\((.*), .+\)

But I need this to be lazy. Otherwise .+) will match the last parenthesis occurrence rather than the first (for example both parenthesis in the end would be replaced with a single one given this string: "NSLog(@"%@", NSSomeFunction(@"hey", @"lol"))" ).

How to do lazy search like this? I think you can do this in pearl using the modifier /U (ungreedy). Though Xcode does not seem to support that.

AndersTornkvist
  • 2,610
  • 20
  • 38
quano
  • 18,812
  • 25
  • 97
  • 108
  • 1
    The `/U` modifier is found in PHP, not Perl, and it makes all quantifiers non-greedy by default, or greedy if followed by `?`. To quote Friedl, "I would guess that the primary effect of this pattern modifier is to create confusion, so I certainly don't recommend it." http://www.oreilly.com/catalog/regex3/index.html – Alan Moore Aug 01 '10 at 21:29

1 Answers1

3

usually the ? will indicate non-greedy match, so for .+) you would use .+?)

ennuikiller
  • 46,381
  • 14
  • 112
  • 137