LoginSignup
10
10

More than 5 years have passed since last update.

Objective-Cの正規表現、キャプチャした変数で文字列置換

Posted at
replace_capturestr.m
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になります。

キャプチャと、リプレイスはこんな感じにできる。すぐ忘れるからメモ代わりに。

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10