Regex to match the first ending HTMl tag

前端 未结 3 456
醉酒成梦
醉酒成梦 2021-01-14 21:00

I am trying to write a regex which match the first ending form tag.

  [^~]* 

The above regex

3条回答
  •  礼貌的吻别
    2021-01-14 21:32

    You should NOT use regular expressions, but parse it with DOM:

    Javascript:

    var forms = document.getElementsByTagName('form');
    forms[0] // is the first form element.
    

    PHP:

    $dom = new DOMDocument();
    $dom->loadHTML( $html );
    $forms = $dom->getElementsByTagName('form');
    $first = $forms->item(0); // reference to first form
    

    You can use minidom and ElementTree for Python.

提交回复
热议问题