1

[[ と ]] と {{ と }} の出現を含む文字列があります。次のコードで [ ] { } が 1 回出現した場合にそのまま維持される正規表現はどれですか?

NSString* initialString = @"[[hi]] {{this}} {is} [a] {{string}}";
NSString* regex = @""; // Which regex would work
NSString* finalString = [match stringByReplacingOccurrencesOfRegex:regex withString:@""];

期待される出力:

こんにちは、これは {is} [a] 文字列です

4

2 に答える 2

0

このようにしてみてください。

NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"[[]]{{}}"];// declare set of unwanted charecters here.
NSString* initialString = @"[[hi]] {{this}} {is} [a] {{string}}";

initialString = [[initialString componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];

O/P:-

 hi this is a string
于 2013-05-09T06:40:41.687 に答える