Google Toolbox for Macã®æ£è¦è¡¨ç¾ã使ã£ã¦ã¿ã
Google Toolbox for Macã®æ£è¦è¡¨ç¾ã使ã£ã¦ã¿ã¾ããã
前回ã¨åæ§ãã¦ã£ã³ãã¦ã«ãã¿ã³ãé ç½®ããã¢ã¯ã·ã§ã³ã«ä»¥ä¸ã®æ§ãªããã°ã©ã ãè¨å®ãã¾ããã
#import "AppController.h" #import "GoogleToolboxForMac/GTMRegex.h" @implementation AppController - (IBAction)run:(id)sender { NSString *str; GTMRegex* regex; NSArray* array; // æ£è¦è¡¨ç¾ã«ä½¿ç¨ããæååãã¨ã¹ã±ã¼ã NSLog(@"--escapedPatternForString:"); str = [NSString stringWithString:@"^.[$()|*+?{\\"]; NSLog(@"%@", [GTMRegex escapedPatternForString:str]); // 0çªç®ã«ãããããæååå ¨ä½ã以éã¯ãµããã¿ã¼ã³ã«ãããããæååãè¿ãã // ããããã¦ããªãå ´å㯠NSNull ã¨ãªãã NSLog(@"--subPatternsOfString:"); regex = [GTMRegex regexWithPattern:@"(fo(o+))((bar)|(baz))"]; array = [regex subPatternsOfString:@"foooooobaz"]; int num = 0; for (NSString *match in array) { NSLog(@"%d: %@", num++, match); } // 0: "foooooobaz" -> ãããããæååå ¨ä½ // 1: "foooooo" -> (fo(o+)) ã«ãããããæåå // 2: "ooooo" -> (o+) ã«ãããããæåå // 3: "baz" -> ((bar)|(baz)) ã«ãããããæåå // 4: NSNull -> (bar) ã«ãããããæåå // 5: "baz" -> (baz) ã«ãããããæåå // æåã«ããããããã®ãè¿ã NSLog(@"--firstSubStringMatchedInString:"); regex = [GTMRegex regexWithPattern:@"foo.bar"]; NSLog(@"%@", [regex firstSubStringMatchedInString:@"foo1barfoo2barfoo3bar"]); // ãããããããBOOLã§è¿ã NSLog(@"--matchesSubStringInString:"); regex = [GTMRegex regexWithPattern:@"foo.bar"]; NSLog(@"%d", [regex matchesSubStringInString:@"foo1bar"]); NSLog(@"%d", [regex matchesSubStringInString:@"foo123bar"]); // ãããããæååãç½®ãæã NSLog(@"--stringByReplacingMatchesInString:withReplacement:"); regex = [GTMRegex regexWithPattern:@"(foo)(.*)(bar)"]; NSLog(@"%@", [regex stringByReplacingMatchesInString:@"foo123bar" withReplacement:@"<b>\\2</b>"]); // NSStringã«ã«ãã´ãªãå®ç¾©ãã¦ãããããNSString ã§ãä»ã¾ã§ã«ç´¹ä»ããã¡ã½ãã㨠// åæ§ãªå¦çãå¯è½ã«ãªã£ã¦ãã¾ã // â»NSString ã®ãã¼ã¿ã¯ãã¿ã¼ã³ã®æååã§ã¯ãªããæ¤ç´¢å¯¾è±¡ã®æååã«ãªãããå¤å° // å¼æ°ãç°ãªããã¨ã«æ³¨æ NSLog(@"--gtm_stringByReplacingMatchesOfPattern:withReplacement:"); str = [NSString stringWithString:@"foo123bar"]; NSLog(@"%@", [str gtm_stringByReplacingMatchesOfPattern:@"(foo)(.*)(bar)" withReplacement:@"<b>\\2</b>"]); } @end
åºåçµæã¯ãããªãã¾ãã
--escapedPatternForString: \^\.\[\$\(\)\|\*\+\?\{\\ --subPatternsOfString: 0: foooooobaz 1: foooooo 2: ooooo 3: baz 4: <null> 5: baz --firstSubStringMatchedInString: foo1bar --matchesSubStringInString: 1 0 --stringByReplacingMatchesInString:withReplacement: <b>123</b> --gtm_stringByReplacingMatchesOfPattern:withReplacement: <b>123</b>
ã¾ããæ£è¦è¡¨ç¾ãã©ã®ããã«å¦çãã¦ããã®ãããã°ã©ã ã確èªããã¨ããå é¨çã«ã¯ regexec() ã¨ããé¢æ°ãå¼ãã§ãã¾ããã
ãã®é¢æ°ãä»ã¾ã§ç¥ããªãã£ããã§ãã調ã¹ãã¨ããCè¨èªã§æ£è¦è¡¨ç¾ãè¡ãé¢æ°ã§ãããGoogleãèªåã§ä½ã£ã¦ããããã®ããªãï¼ã¨æã£ã¦ãã®ã§ã¡ãã£ã¨æ®å¿µã§ããã
Manpage of REGEX
http://www.linux.or.jp/JM/html/LDP_man-pages/man3/regex.3.html
ãã¬ã¼ã ã¯ã¼ã¯ã®ããã°ã©ã å 㧠REG_EXTENDED ãã»ãããã¦ããããæ£è¦è¡¨ç¾ã¨ãã¦ã¯ãPOSIX æ¡å¼µæ£è¦è¡¨ç¾ãã使ããããã§ãã
ãã®ããPerlã¬ãã«ã®åã£ãæ£è¦è¡¨ç¾ã¯ç¡çã§ããã¡ãã£ã¨ããæ£è¦è¡¨ç¾ãå¿ è¦ãªã¨ããªã©ã«ã¯ä¾¿å©ã«ä½¿ãããã§ãã
ã¡ãªã¿ã«æ£è¦è¡¨ç¾ã«ã¤ãã¦ãã¡ãã®æ¬ãªã©ãè©å¤è¯ãã§ãã
- ä½è : Jeffrey E.F. Friedl,æ ªå¼ä¼ç¤¾ãã³ã°ãã¼ã«,é·å°¾é«å¼
- åºç社/ã¡ã¼ã«ã¼: ãªã©ã¤ãªã¼ã¸ã£ãã³
- çºå£²æ¥: 2008/04/26
- ã¡ãã£ã¢: 大åæ¬
- è³¼å ¥: 24人 ã¯ãªãã¯: 754å
- ãã®ååãå«ãããã° (82件) ãè¦ã
æ£è¦è¡¨ç¾ã®è¯ã使ããã¿ã¼ã³ã®ä¾é¡ãè¼ã£ã¦ãã¦å®è·µã«ãã使ãã¦ä¾¿å©ã§ãã
å¾ãå種ç°å¢ãè¨èªå¥ã®æ¹è¨ã«ã¤ãã¦è¼ã£ã¦ããã®ãè¯ãã£ãã§ãã
æ£è¦è¡¨ç¾ãã³ããã㯠(Technical Handbook Series)
- ä½è : 鹿島åé,åææä¸,æ¨æ浩ä¸
- åºç社/ã¡ã¼ã«ã¼: ã½ãããã³ã¯ã¯ãªã¨ã¤ãã£ã
- çºå£²æ¥: 2005/06/30
- ã¡ãã£ã¢: åè¡æ¬
- è³¼å ¥: 7人 ã¯ãªãã¯: 98å
- ãã®ååãå«ãããã° (12件) ãè¦ã