Created
July 2, 2013 14:49
-
-
Save AyatoKinkori/5909926 to your computer and use it in GitHub Desktop.
Objective-Cの正規表現、キャプチャした変数で文字列置換 ref: http://qiita.com/AyatoKinkori@github/items/750af1bcade414f4effc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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