Re: how to get this type of regex matching happening (using AGRegex)?
Re: how to get this type of regex matching happening (using AGRegex)?
- Subject: Re: how to get this type of regex matching happening (using AGRegex)?
- From: Ben Dougall <email@hidden>
- Date: Sun, 21 Mar 2004 13:04:55 +0000
On Saturday, March 20, 2004, at 06:24 pm, Aram Greenman wrote:
AGRegex *regex = [[AGRegex alloc] initWithPattern:@"anchor
((\\w)\\s*)*"];
example input text 1:
anchor a b c d
hoped for array from example text 1:
a
b
c
d
Each set of parentheses only remembers the last occurrence of the
subpattern. You'll probably have to use two regexes.
AGRegex *re1 = [AGRegex regexWithPattern:@"anchor (((\\w)\\s*)*)"];
NSString *s = [[re1 findInString:@"anchor a b c d"] groupAtIndex:1];
// s should now be "a b c d"
AGRegex *re2 = [AGRegex regexWithPattern:@"(\w)\\s*"];
NSArray *matches = [re2 findAllInString:s];
// matches is an array of AGRegexMatches
matches[0] = {"a ", "a"}
matches[1] = {"b ", "b"}
matches[2] = {"c ", "c"}
matches[3] = {"d", "d"}
I'm guessing this is probably a simplified example of what you really
want to do,
yes -- wanted to illustrate the general regex problem that i've come
across of fixed storage for results from capture brackets, in
conjunction with looping the capture brackets in the regex -- i was
hoping and thought there might be a way to get accumulation of the
results happening from within the regex pattern as much as possible (as
in a single pattern), rather than also using extra obj-c or/and further
patterns.
ok, will give your suggested way a go.
thanks-a-lot, ben.
_______________________________________________
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.