Regular matching to multiple results, how to take the last result?

for example, the content is like this

<div>
<ul>
//
<li>aaaaa</div>
//
<li>bbbbb</li>
//
<li>cccccc</li>
//
<li>ddddd</li>
//
</ul>
</div>
The actual content of

will be much more complicated than this.
what I hope to match is dddd ,
my regular expression (

  • (. *)
  • ) ,

    The result of

    match is

    <li>aaaaa</li>
    <li>bbbbb</li>
    <li>cccccc</li>
    <li>ddddd</li>

    how do I match the last result directly with the rule? Or match to any one of the results?

    I"m convinced, too. I"m just asking about regularities. Here comes java, js, and PHP. I just want a regularization.

    Mar.22,2021

    you can use forward preview to match the last one

    /<li>(.*)<\/li>(?![\s\S]*?<li>(.*)<\/li>)/
    

    if you match the specified position, you can only use array subscript

    .

    str.match (/ > (\ w+) < / gi). Pop (). Replace (/ < | > / ig,'')


    this kind of thing had better not use regular, if it is java, you can use jsoup.jar


    generally regex.match (text) will return a list, and take the last element of list.


    Brother you can create an array and put everything that matches into it, just take the last element of the array.

    Menu