Re: MOKit
Re: MOKit
- Subject: Re: MOKit
- From: Brock Brandenberg <email@hidden>
- Date: Sat, 10 Aug 2002 18:06:31 -0500
Hi Nico.
MOKit is pretty easy to use. Mike did a nice job implementing it and
provided a nice function to do the subexpression substitution.
To create a regular expression object:
MORegularExpression *regex = [[MORegularExpression alloc]
initWithExpressionString:@"(.*)my(.*)" ignoreCase:YES];
To use it to find matches in a string:
NSMutableString *testString = [NSMutableString stringWithString:@"This is my
string."];
BOOL matches = [regex matchesString:testString];
if( matches )
{
[testString setString:substituteSubexpressions( regex, @"\\1your\\2",
testString )];
}
A couple points to remember: Note the double escaped characters in the
substituteSubexpressions() parameter. You'll need to do this in string
literals, but not if you're pulling the strings from text fields in a UI.
Also, you cannot re-use a regex. If you need to change the expression
string, you'll need to release the regex and create a new one.
This should get you pointed in the right direction. If you're unfamiliar
with regular expressions, you'll have a bit of reading to do before going
much further though.
Good luck,
Brock Brandenberg
----- industrial design @ www.bergdesign.com ------
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.