Parsing HTML NSRegularExpression

后端 未结 1 1060
逝去的感伤
逝去的感伤 2021-01-17 02:43

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

STRING THA
相关标签:
1条回答
  • 2021-01-17 03:04

    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>.

    0 讨论(0)
提交回复
热议问题