Skip to content

Instantly share code, notes, and snippets.

@AyatoKinkori
Created July 2, 2013 14:49
Show Gist options
  • Save AyatoKinkori/5909926 to your computer and use it in GitHub Desktop.
Save AyatoKinkori/5909926 to your computer and use it in GitHub Desktop.
Objective-Cの正規表現、キャプチャした変数で文字列置換 ref: http://qiita.com/AyatoKinkori@github/items/750af1bcade414f4effc
NSString *str = @"hogehogefugao";
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:@"(hoge).+(fugao)" options:0 error:nil];
NSString *new_str = [regexp
stringByReplacingMatchesInString:str options:0 range:NSMakeRange(0, str.length) withTemplate:@"$1山$2"];
//new_strは hoge山fugaoになります。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment