Help us understand the problem. What is going on with this article?

Obj-Cで正規表現使うならRegexKitLite

More than 5 years have passed since last update.

objective-cの正規表現はめんどくさい。
そこでRegexKitLite。これをimportするとNSStringクラスに正規表現な諸々の関数が追加される。

stringByMatchingを呼ぶだけで一致文字列を取得

#import "RegexKitLite.h"

...

NSString *hoge = @"Hello world!!!";
NSString *match = [hoge stringByMatching:@"[a-z]*!"];

NSLog (@"%@", match);  // world!

マッチグループを配列に入れるのも簡単

NSString *url = @"http://hogehoge/api/city=1234";
NSArray *matchArray = [url captureComponentsMatchedByRegex:@"city=([0-9]*)"];

NSLog(@"%@", matchArray[0]);  // city=1234
NSLog(@"%@", matchArray[1]);  // 1234

もちろんCocoaPodsにもあるよ

pod 'RegexKitLite', '4.0'
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした