• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSString and regular expressions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString and regular expressions


  • Subject: Re: NSString and regular expressions
  • From: BareFeet <email@hidden>
  • Date: Tue, 4 Aug 2009 13:10:31 +1000

Hi All,

RegexKitLite looks promising. It claims to only require you to add the .h and .m file to your project and link to the libicucore.dylib library.

I managed to incorporate RegexKitLite fairly easily once I found in the documentation the steps to link to the libicucore.dylib library.


Thanks for all your comments about ICU vs PCRE. I've thrown a couple of fairly involved regexes at it that I've previously used in Perl (therefore PCRE) and haven't had to make any adjustments at all.

I've wrapped it in a test Cocoa app that shows capture in an outline view, with each group showing as a child item of its capture. It's working very well so far. The essence of my use of RegexKitLite here is:

- (IBAction)update:(id)sender
{
NSString * regexString = [regexField string];
NSString * inputString = [inputField string];

[outputArray release]; // already defined as an instance variable in the .h file
NSError * myError = nil;
NSRange myRange = NSMakeRange(0, [inputString length]);
outputArray = [inputString arrayOfCaptureComponentsMatchedByRegex:regexString options:RKLNoOptions range:myRange error:&myError];
[outputArray retain];
[outputOutline reloadData];
}
@end


I'm new to Cocoa and Objective-C. So please tell me gently of any glaring errors above

Now to use it in my real project, I need to port over my routines that parsed SQL statements. I have been doing this by:

1. Using regex to replace quoted items (eg bounded by " or ' or a comment bounded by /* */ or -- \n) with placeholders.

2. Using regex to parse the SQL (now containing placeholders) into desired SQL components

3. Replacing placeholders with original text.

Before I go ahead and port this same method across, is there any built in functionality in Cocoa that will facilitate this (or part of it) directly?

Thanks,
Tom
BareFeet

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Avoiding KVO in dealloc?
  • Next by Date: AGRegex (was: NSString and regular expressions)
  • Previous by thread: Re: Avoiding KVO in dealloc?
  • Next by thread: AGRegex (was: NSString and regular expressions)
  • Index(es):
    • Date
    • Thread