Using a regular expression to match a div block having a specific ID

前端 未结 5 1811
野性不改
野性不改 2021-01-03 06:42

I\'m trying to match a block of div that have a particular id.. Here\'s my regex code:

]*\\s*id\\s*=\\s*[\"|\']content[\"|\']\\s*>[^/div]         


        
5条回答
  •  青春惊慌失措
    2021-01-03 07:29

    The [^/div]+ will stop when it reaches any of those characters, which is not what you want. As it'll stop when it reaches too because of the i.

    Unfortunately, you can't do what you want without knowing the internal structure of the HTML in the first place. Consider this:

    Even if you could construct a regexp that would match up till the

    , you can't construct one that will match up until the correct
. You need to do a much more intensive parsing.

提交回复
热议问题