Re: Fastest/smallest search+replace
Re: Fastest/smallest search+replace
- Subject: Re: Fastest/smallest search+replace
- From: Greg Titus <email@hidden>
- Date: Mon, 14 May 2001 19:22:02 -0700
Hey John,
Thought I'd mention OFRegularExpression to the list here, even though I
know you know about it. (I think you've even posted pointers to it
before on the macosx-dev list...) Do you have issues with our
implementation, or just think this would be something that should be
built into Cocoa by Apple?
The OmniFoundation framework at
http://www.omnigroup.com/community/developer/sourcecode includes a
couple of regular expression classes OFRegularExpression and
OFRegularExpressionMatch. They handle full Unicode regex's and strings.
On Monday, May 14, 2001, at 03:16 PM, John C. Randolph wrote:
>
Yes, and while you're at it, how about a good selection of the rest of
>
the string-bashing functionality that Perl or Python offer? In
>
particular, the tr/// operator would be *very* nice to have, and a
>
"NSRegex" class that kept the compiled expressions around would be a
>
nice addition to the NSScanner functionality.
The OF equivalent code for these is:
>
nameExpression = [[NSRegex alloc] initWithPattern:@"[A-Za-z]*"];
nameExpression = [[OFRegularExpression alloc]
initWithString:@"[A-Za-z]*"];
>
[myScanner scanPattern:nameExpression intoString:&nameString];
match = [nameExpression matchInScanner:myScanner];
nameString = [match matchString];
>
[myMutableString searchForPattern:nameExpression
>
andReplaceWithString:@"Some Other Name"];
match = [nameExpression matchInString:myMutableString];
[myMutableString replaceCharactersInRange:[match matchRange]
withString:@"Some Other Name"];
Cheers!
--Greg