V S V S - 1 year ago 83
iOS Question

How to remove line contains starting with NSLog iOS?

I have NSLogs in code, so many time. A easy solution is that I replace with

NSLog(@ with //NSLog(@

But, If I want to remove all the lines, starting with NSLog, what can I do?


Answer Source

In Xcode just search and replace from the Project Navigator. You can select "Starting with", "Contains", "Regular Expression", etc.

Using Regular Expression ^[\s\W]+NSLog.*$ should work well for lines that might have a tab or space before the NSLog but won't catch lines with other text that may be in front of it. (notice in the second screen shot NSLog was detected at the end of the line, while the first didn't).

Another example might be if you want to keep commented NSLog lines and remove the others:


Would remove NSLog on line 3 and NSLog(@"%@",removed); on line 7.

// NSLog
/* NSLog */

NSString *NSLog = @"not nslog"


Additional Examples:

enter image description here enter image description here enter image description here