• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how to get this type of regex matching happening (using AGRegex)?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: John Clayton <email@hidden>
  • Date: Thu, 25 Mar 2004 14:19:57 -0500

Hi Ben,

I haven't tried this, but what about using something like:


AGRegex *regex = [AGRegex regexWithPattern:@"(anchor\\s*)?((\\w)\s)"];
NSArray *matches = [regex findAllInString:@"anchor a b c"];
int i;
for(i = o; i < [matches count]; i++) {
AGRegexMatch *match = [matches objectAtIndex:i];
NSLog(@"match is %@",match);
}


Sorry I just noticed this, a week later, heh.


Hope that helps, John.




On Mar 19, 2004, at 1:08 PM, Ben Dougall wrote:

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.


Regards,

John Clayton
--------------------------
Software Developer
Online Channel Development

email@hidden
201.748.5717
_______________________________________________
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.


References: 
 >how to get this type of regex matching happening (using AGRegex)? (From: Ben Dougall <email@hidden>)

  • Prev by Date: Re: Copy File/ Shell Script Phase
  • Next by Date: Vending a proxy problems
  • Previous by thread: how to get this type of regex matching happening (using AGRegex)?
  • Next by thread: Re: how to get this type of regex matching happening (using AGRegex)?
  • Index(es):
    • Date
    • Thread