それはあるべきです:-)
NSString * stringToParse = @"{\"query\":{\"normalized\":[{\"from\":\"May_21\",\"to\":\"May 21\"}],\"pages\":{\"19684\":{\"pageid\":19684,\"ns\":0,\"title\":\"May 21\",\"revisions\":[{\"*\":\"==Events==\\n* [[293]] – Roman Emperors [[Diocletian]] and [[Maximian]] appoint [[Galerius]] as [[Caesar (title)|''Caesar'']] to Diocletian, beginning the period of four rulers known as the [[Tetrarchy]].\\n* [[878]] – [[Syracuse, Italy]], is [[Muslim conquest of Sicily|captured]] by the ...";
//Replace &ndash with -
stringToParse = [stringToParse stringByReplacingOccurrencesOfString:@"&ndash" withString:@"-"];
//[[Caesar (title)|''Caesar'']] Should be Caesar
//and [[Maximian]] should be Maximian
//same for [[1972]] -> 1972
NSString *regexToReplaceWikiLinks = @"\\[\\[([A-Za-z0-9_ ()]+?\\|)?(\\'\\')?(.+?)(\\'\\')?\\]\\]";
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexToReplaceWikiLinks
options:NSRegularExpressionCaseInsensitive
error:&error];
// attention, the found expression is replacex with the third parenthesis
NSString *modifiedString = [regex stringByReplacingMatchesInString:stringToParse
options:0
range:NSMakeRange(0, [stringToParse length])
withTemplate:@"$3"];
NSLog(@"%@", modifiedString);
結果:
{"query":{"normalized":[{"from":"May_21","to":"May 21"}],"pages":{"19684":{"pageid":19684,"ns":0,"title":"May 21","revisions":[{"*":"==Events==\n* 293 -; Roman Emperors Diocletian and Maximian appoint Galerius as Caesar to Diocletian, beginning the period of four rulers known as the Tetrarchy.\n* 878 -; Syracuse, Italy, is captured by the ...