0

In xCode I want to look for my NSLog statements that are not prefaced by a { from the previous line.

So I want to not find:

if (debug) {
    NSLog(@"MyDebug");
}

and only find.

  x=y+3;
  NSLog(@"MyDebug %d",x);

I was thinking something like : (?<!\{\r.*NSLog).*NSLog or (?<!\{)\r.*NSLog(?!\{) though that does not seem to get me anything.

Nightfirecat
  • 11,432
  • 6
  • 35
  • 51
scooter133
  • 1,297
  • 1
  • 15
  • 29
  • 1
    AFAIK, Xcode regexen cannot match across lines. You can add new lines in your replacement, but you can't match across lines in your pattern. Other tools are not so limited; perhaps try grep? – Jeremy W. Sherman Oct 19 '11 at 22:52
  • If I'm reading correctly, multiline (`\n`) works as of 2015. – Clay Bridges Dec 08 '15 at 14:58

1 Answers1

2

As Jeremy mentioned in the comments, Xcode doesn't support regexes that match multiple lines. However, according to this message in a thread on xcode-users, you can search for newline characters using non-regex search:

Xcode's Find and Project Find don't support multiline regular expressions. They do support multiline text find...

(A subsequent message in the thread indicates that you can type a newline using option-return.)

If you know the line above the one you wish to match will always end with ;, you could leverage that in a non-regex search.

As for grep, unfortunately it doesn't really like to match multiple lines. pcregrep may be more useful.

Community
  • 1
  • 1
Jason Plank
  • 2,336
  • 5
  • 31
  • 40
  • Not Perfect as there are a variable number of spaces between the ; and NSLOG, but its much closer.. Thanks! – scooter133 Dec 15 '11 at 17:19