I have downloaded the RegexKitLite program to use for Regular Expressions.
What I need to do is capture from a web page all the data between the first instance of a div with its class as definition.
<div class='definition'> capture data between these tags </div>
I've solved the problem of how to get the web page loaded into a string but cannot figure out the correct regular expression. I use the regular expression
(?<=<div class='definition'>).*?(?=</div>). This works when I test it on a test string in the program such as :-
NSString *test = @"gfhfghfg<div class='definition'>test5678</div>llkklkkl";
NSLog(@"Match: %@", [test stringByMatching:regex capture:0]);
Result is :- Match: test5678
When I use it on the web page it doesn't work for some reason:-
NSData *response = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: &resp error: &err];
NSString * theString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSString* regex = @"<div class='definition'>(.*?)</div>";
NSLog(@"Match: %@", [theString stringByMatching:regex capture:0]);
Result is :- Match(null)
However if I change regex = @"<div class='definition'>(.*?)"
Result is :- Match: <div class='definition'>
which is not much use!
Could it be a problem with the encoding it is converted to UTF8.
Is anyone an expert on regular expressions or had a similar problem.
Thanks.
What I need to do is capture from a web page all the data between the first instance of a div with its class as definition.
<div class='definition'> capture data between these tags </div>
I've solved the problem of how to get the web page loaded into a string but cannot figure out the correct regular expression. I use the regular expression
(?<=<div class='definition'>).*?(?=</div>). This works when I test it on a test string in the program such as :-
NSString *test = @"gfhfghfg<div class='definition'>test5678</div>llkklkkl";
NSLog(@"Match: %@", [test stringByMatching:regex capture:0]);
Result is :- Match: test5678
When I use it on the web page it doesn't work for some reason:-
NSData *response = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: &resp error: &err];
NSString * theString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSString* regex = @"<div class='definition'>(.*?)</div>";
NSLog(@"Match: %@", [theString stringByMatching:regex capture:0]);
Result is :- Match(null)
However if I change regex = @"<div class='definition'>(.*?)"
Result is :- Match: <div class='definition'>
which is not much use!
Could it be a problem with the encoding it is converted to UTF8.
Is anyone an expert on regular expressions or had a similar problem.
Thanks.