Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Using regex.h

Using regex.h
Thread Tools
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Nov 26, 2004, 05:19 AM
 
Hi guys,

I've been told I can use regex.h for powering the regular expression searches in my app. I'm never actually touched pure C code (is regex.h C?), so I've really got no idea how to implement it in a Cocoa based application.

I guess I could use NSTask, but I think that could cause major slowdowns. I also know about the OmniFrameworks and others (MOKit etc.), but I'd rather cook up my own engine if possible. Any help is appreciated.

Thanks,
Oliver
     
Professional Poster
Join Date: Sep 1999
Location: Ottawa, ON, Canada
Status: Offline
Reply With Quote
Nov 26, 2004, 09:34 AM
 
Originally posted by iOliverC:
Hi guys,

I've been told I can use regex.h for powering the regular expression searches in my app. I'm never actually touched pure C code (is regex.h C?), so I've really got no idea how to implement it in a Cocoa based application.

I guess I could use NSTask, but I think that could cause major slowdowns. I also know about the OmniFrameworks and others (MOKit etc.), but I'd rather cook up my own engine if possible. Any help is appreciated.
Do you use Obj-C in Cocoa? If so, then you already use C. Include the header, and call the functions whenever you need to parse something. You should be able to find the docs on regex anywhere on the web.
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Nov 26, 2004, 10:02 AM
 
Originally posted by hayesk:
Do you use Obj-C in Cocoa? If so, then you already use C. Include the header, and call the functions whenever you need to parse something. You should be able to find the docs on regex anywhere on the web.
I did a 'man regex' in the Terminal and gave it a read. Seems I have to do:

#include <regex.h>

I also realised there are 4 functions, but I only need to use 2. I seem to need to provide regcomp with a regular expression string, it will then transform that into a internally structured correct one. I then need to pass that and the string I want to parse into regexec.

I understand all the theory work, but I'm still at a lost as to how to use these functions, for example, in Obj-C, I would do something like:

NSString *hello = [regex parseString:@"hello" withExpression:expression];

Any sort of C method example could help

Thanks,
Oliver
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:22 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2