Reputation: 1176
I need to match a string that has either a prefix, or a suffix.
So far, I've done this:
(?i)(?:(?:Localized(?:App)?String\(@))?\"(.+?)\".(?:localized)?
Testing this regex against the scenario below, it works well, except for the first line, where I should have no matches:
print("Error: should NOT capture!")
NSLocalizedAppString(@"Contextual Menu",nil)];
self.setTitleStates(["Unmute1".localized, "Mute".localized])
NSApplication.localizedString("Paused", comment: "")
print("Remove from Set".localized)
How do I mutually exclude the prefix group with the suffix group?
Thanks!
Upvotes: 1
Views: 325
Reputation: 626870
You can use
(?si)Localized(?:App)?String\(@?"([^"\\]*(?:\\.[^"\\]*)*)"|"([^"\\]*(?:\\.[^"\\]*)*)"\.localized
See the regex demo. Details:
(?si)
- dot now matches line breaks and i
makes the pattern case insensitiveLocalized
- a word(?:App)?
- an optional App
stringString\(
- a String(
text@?
- an optional @
"([^"\\]*(?:\\.[^"\\]*)*)"
- a "..."
string literal pattern with escape sequences support|
- or"([^"\\]*(?:\\.[^"\\]*)*)"
- a "..."
string literal pattern with escape sequences support\.localized
- .localized
string.Upvotes: 1