Skip to content Skip to sidebar Skip to footer

Parsing HTML NSRegularExpression

i'm trying to parse an HTML page using NSRegularExpressions.. The page is a repetition of this html code:
STRING THAT I WANT

Solution 1:

Try using this regex:

 @"<div class=\"fact\" id=\"fact[0-9]*\">([^<]*)</div>"

Regex:

fact[0-9].*

means: fact followed by a number between 0 and 9, followed by any character repeated any number of times.

I also suggest using:

([^<]*)

instead of

(.*)

to match between the two divs so to deal with regex greediness, or alternatively:

(.*?)

(? will make the regex non-greedy, so it stops at the first instance of </div>.


Post a Comment for "Parsing HTML NSRegularExpression"