Skip to content

Instantly share code, notes, and snippets.

@nantekkotai
Created May 31, 2012 06:48
Show Gist options
  • Select an option

  • Save nantekkotai/2841538 to your computer and use it in GitHub Desktop.

Select an option

Save nantekkotai/2841538 to your computer and use it in GitHub Desktop.
Objective-Cで正規表現

以下サンプルコード。

NSString *originStr = @"abogado ga umai!";
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:@"umai"
                                                                        options:0
                                                                          error:nil];

// ここでは置換してみる
NSString *replaced = [regexp stringByReplacingMatchesInString:originStr
                                                      options:0
                                                        range:NSMakeRange(0, originStr.length)
                                                 withTemplate:@"mazui"];

NSLog("replaced = %@", replaced);    // -> "abogado ga mazui!"

たぶんちゃんと動く(未検証)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment