The context is an IOS app. I would like to replace white spaces enclosed by brackets.
ex:
Toto "is Bill" should become Toto "is#Bill"
The weather is "bright and clear" should become The weather is "bright#and#clear"
I have made trials using the following code based on another post
NSString *pattern = @"(?:(?<=^\")(\\s+))|(?:(?!^\")(\\s+)(?=.))|(?:(\\s+)(?=\"$))"; // (?:(?<=^")(\s+))|(?:(?!^")(\s+)(?=.))|(?:(\s+)(?="$))
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:&error];
NSString *modifiedString = [regex stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:@"#"];
NSLog(@"modified %@", modifiedString);
But this is not working right.
all spaces are replaced (Toto#"is#Bill")
I get the same result with just (?:(?!^")(\s+)(?=.))
I have made one on my own (?:\"\S*)(\s)(?:\S*) which is not ok neither
I will appreciate help on this! Thanks