{"id":24,"date":"2006-12-27T20:19:26","date_gmt":"2006-12-27T19:19:26","guid":{"rendered":"http:\/\/www.spikesoft.ch\/?p=24"},"modified":"2009-04-08T17:55:45","modified_gmt":"2009-04-08T16:55:45","slug":"regular-expressions-in-objective-c","status":"publish","type":"post","link":"https:\/\/www.spikesoft.ch\/?p=24","title":{"rendered":"Regular Expressions in Objective-C"},"content":{"rendered":"<p>This class allows you to use very powerfull regular expressions (because it&#8217;s based on regexec from C) in an object oriented way.<br \/>\nThanks to the <a href=\"http:\/\/tearesolutions.com\/2006\/09\/how_to_use_regular_expressions_1.html\" target=\"_blank\">post<\/a> of David Teare, I finally find a very easy and powerfull solution for using regular expressions in Objective-C. David&#8217;s code only returns a boolean to indicate if the NSString was matching the given regular expression. I improve its method by returning a NSMutableArray with the different sub-expressions that lead to a match. Unfortunately I wasn&#8217;t able to return nil when the sub-expression doesn&#8217;t produce a match, instead I return the empty NSString @&#8221;&#8221;.<\/p>\n<p>Download <a id=\"p25\" href=\"http:\/\/www.spikesoft.ch\/wordpress\/upload\/2006\/12\/restring.zip\">Regular Expression Source Code<\/a><\/p>\n<p>[Updated the 16.05.2007]  Thanks to everybody for you remarks, I updated the source file accordingly. I also add a example script to demonstrate the use of the method.<\/p>\n<p>Download <a title=\"restring-11.zip\" href=\"http:\/\/www.spikesoft.ch\/wordpress\/upload\/2007\/06\/restring-11.zip\">Regular Expression Source Code version 1.1<\/a><\/p>\n<p>[Updated the 01.01.2008] After receiving a reader&#8217;s mail about the code&#8217;s licencing, I clarify the situation and add the GPL licence in the header as well as the full licence in the package.<\/p>\n<p>Download\u00a0 <a title=\"restring-11.zip\" href=\"http:\/\/www.spikesoft.ch\/wordpress\/upload\/2007\/06\/restring-11.zip\">Regular Expression Source Code version 1.1<\/a><\/p>\n<p>[Update 22.02.2009] Hey I just discovered that <a href=\"http:\/\/twitterfon.net\/\" target=\"_blank\">TwitterFon<\/a>, <a href=\"http:\/\/ymail2.sourceforge.net\/\" target=\"_blank\">YMail<\/a> and <a href=\"http:\/\/code.google.com\/p\/swisssms\/\" target=\"_blank\">swisssms<\/a> are using this <a href=\"http:\/\/www.naan.net\/trac\/browser\/trunk\/TwitterFon\/Classes\/OtherSources\" target=\"_blank\">class<\/a>. Cool isn&#8217;t it.<\/p>\n<p>[Updated the 08.04.2009] Bugfix the behavior when working on NSString with UTF8 encoded chars. Thanks to Ian Atha &amp; soniccat for the correction<\/p>\n<p>Download <a title=\"restring-12.zip\" href=\"http:\/\/www.spikesoft.ch\/wordpress\/upload\/2006\/12\/restring-12.zip\">Regular Expression Source Code version 1.2<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This class allows you to use very powerfull regular expressions (because it&#8217;s based on regexec from C) in an object oriented way. Thanks to the post of David Teare, I finally find a very easy and powerfull solution for using &hellip; <a href=\"https:\/\/www.spikesoft.ch\/?p=24\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,9],"tags":[],"class_list":["post-24","post","type-post","status-publish","format-standard","hentry","category-objective-c","category-programmation"],"_links":{"self":[{"href":"https:\/\/www.spikesoft.ch\/index.php?rest_route=\/wp\/v2\/posts\/24","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spikesoft.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spikesoft.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spikesoft.ch\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spikesoft.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=24"}],"version-history":[{"count":6,"href":"https:\/\/www.spikesoft.ch\/index.php?rest_route=\/wp\/v2\/posts\/24\/revisions"}],"predecessor-version":[{"id":518,"href":"https:\/\/www.spikesoft.ch\/index.php?rest_route=\/wp\/v2\/posts\/24\/revisions\/518"}],"wp:attachment":[{"href":"https:\/\/www.spikesoft.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spikesoft.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spikesoft.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}