Andrew
Andrew

Reputation: 351

Find hardcoded strings but not those for file names (Xcode, Regex help)

I am searching for all hardcoded strings in my app so I can localize them. Currently I am using the regular express search for @"[^"]+" as suggested in this answer: Searching hard coded text in xcode

The issue is I want to only find some strings in this format. For example, I want to exclude [UIImage imageNamed:@"string"] and NSLog(@"Log string"). I believe the easiest way to do this is find a string of the format of @"[^"]+" as long as the prior characters do not include NSLog(, or imageNamed:, or several other things I will enter in manually.

How can I write a regex that excludes these cases?

Upvotes: 10

Views: 5144

Answers (3)

Sasan Soroush
Sasan Soroush

Reputation: 925

I think this would be more comprehensive

"[a-zA-Z0-9 ?!.,;/\-=+)(*&%#@]+"

Search > Find > Regular Expression -- type

enter image description here

enter image description here

Upvotes: 4

Ahmed Lotfy
Ahmed Lotfy

Reputation: 3906

For Swift project

In Xcode > Search > Find > Regular Expression -- type "[a-zA-Z0-9]+"

enter image description here

Upvotes: 4

Soheil
Soheil

Reputation: 795

You can use a negative lookbehind to exclude those cases:

(?<!(imageNamed:|NSLog\())@"[^"]+"

Upvotes: 12

Related Questions