0

I have HTML with a lot of strings in this format :

<li><a href="#track_info_page?artist=text&title=text">

And I want to get an array of this string with this Regex :

NSString *regex = [NSString stringWithFormat:@"<li><a href=\"#track_info_page?(.*?)\">"];

NSArray * arr = [html componentsMatchedByRegex:regex capture:1L];

But the NSArray is always empty. Any idea what can be the problem ?

YosiFZ
  • 7,466
  • 20
  • 105
  • 206

1 Answers1

1

Try with this regex:

NSString *regex = [NSString stringWithFormat:@"<li><a href=\"#track_info_page\\?(.*?)\">"];

The first ? shall be escaped; page? will match pag and page but not page?.

Also keep in mind that regexs are not a suitable means to full html parsing, so if you plan to do complex things, at some point you will stumble in some blocking point.

Community
  • 1
  • 1
sergio
  • 68,479
  • 11
  • 101
  • 120