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

前端 未结 5 1774
野性不改
野性不改 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:48

    .*?

    is what you need - as long as you don't have nested divs. If you do have them, give up and use an actual XML parser.

    Switch on the "dotall" option though (check http://www.regular-expressions.info/dot.html and find out how to do that with your regex flavour).

    Minor details up to you. :-)

提交回复
热议问题