how to get this type of regex matching happening (using AGRegex)?
how to get this type of regex matching happening (using AGRegex)?
- Subject: how to get this type of regex matching happening (using AGRegex)?
- From: Ben Dougall <email@hidden>
- Date: Fri, 19 Mar 2004 18:08:49 +0000
hiyer,
i'm trying to have the various parts of a match split up by using the
bracket ( ) memory/splitting capability in regex and looping a variable
number of times (using a * following the brackets) -- and have the
results, however many there are of them, build up in an array. it's
that last bit i can't work out as ( )'s have a specific fixed place to
their store results, so'll keep over-writing results rather than
accumulating their results letting the results build up in different
positions in an array.
simple example to show what i mean:
example input text 1:
anchor a b c d
hoped for array from example text 1:
a
b
c
d
example input text 2:
anchor a b
hoped for array from example text 2:
a
b
my attempt:
AGRegex *regex = [[AGRegex alloc] initWithPattern:@"anchor
((\\w)\\s*)*"];
NSLog(@"%@", [regex findInString:@"anchor a b c d"] );
NSLog(@"%@", [regex findInString:@"anchor a b"] );
outputs:
2004-03-19 17:36:56.491 regexTest[27912] <AGRegexMatch: 0x5e250> {
0 {0, 14} anchor a b c d
1 {13, 1} d
2 {13, 1} d
}
2004-03-19 17:36:56.555 regexTest[27912] <AGRegexMatch: 0x62e10> {
0 {0, 10} anchor a b
1 {9, 1} b
2 {9, 1} b
}
so there's the problem i mentioned -- the results aren't accumulating
-- they're obviously going into the same place over and over hence why
the array is only left with the last single result (there's two because
there's two sets of brackets in the pattern).
how can i be left with each match rather than just the last? maybe i
shouldn't be attempting to do it with brackets/capturing at all --
maybe there's another way (using regex though)?
thanks, 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.