iOS Struggling with regular expressions

isthisonetaken

macrumors regular
Original poster
Jun 29, 2006
123
0
Hey All,

I have an app that gets some returned data from a website and stores it in an NSString. The returned data is HTML with some information I want to get that's dynamic (it's always different when the data is returned). The stuff I'm looking for is buried within the HTML in lines like this:

<td align="center" colspan="1"> <a class="ada" title="11:00 P.M.">11:00 P.M.</td><td align="left" colspan="1"> TO Some Destination</td>

I tried using an XML scanner, but it kept failing out with errors not liking the way the returned code was formatted I guess. After doing some Googling, it seems I should be using regular expressions to do a search through the string to find the data. I have this so far:

Code:
// create a regex to find the times in the returned string
    NSRegularExpression *timeRegex = [[NSRegularExpression alloc] initWithPattern:@""
                                                                          options:NSRegularExpressionCaseInsensitive error:nil];
    // find an array of the times
    NSArray *times = [timeRegex matchesInString:self.returnedDataString options:0 range:NSMakeRange(0, [self.returnedDataString length])];
My problem is the regex expression which right now is @"", which obviously isn't what I want. I read about regular expressions, but still don't really know how to start? I should mention as well that there are normally multiple times and occasionally no times returned.

Any thoughts or help?
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
8,615
4,086
I'm not quite sure how to do what you want, but an idea I have would be, if times are always given in A.M. Or P.M. (as opposed to 24 hour time, my preferred format,) then you could search for the string ".M." - it seems quite improbable that that series of characters would appear outside of a string giving the time. Then just look at the characters before that.
 
Comment

Similar threads

Replies
0
Views
576
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.