1

I have a html file containing ol list of items, each item has the pattern <li id=ref>xxxxx</li>, the id "ref" is unique to this list. I want to add a closing </ol> after the last item. so I use negative look-ahead to see if the next line has the same id (next line could be any text), if not, </ol> tag will be inserted. this is my code

$html =~ s`(<li id="ref.*?</li>).*?(?!\<li id="ref)`$1</ol>`gm; 

the code does not work no matter I use the modifier s or m at the end of the code.

TLP
  • 66,756
  • 10
  • 92
  • 149
Eric
  • 21
  • 3
  • 4
    You should not [parse HTML with regex](https://stackoverflow.com/q/1732348/725418). Also, you cannot match multiple lines when reading a file in line by line mode. – TLP Jun 26 '21 at 00:45
  • `/m` has no effect since your pattern uses neither `^` nor `$`. – ikegami Jun 26 '21 at 01:58
  • `/s` is probably required since it remove the inability of `.` to match line feeds. But you did not provide a minimal, runnable demonstration of the problem, so I can't be sure. – ikegami Jun 26 '21 at 01:58

1 Answers1

1

Thank you for your replying. I manged to get it to work by using the following code:

$html =~ s`</li>(?!.*?id\=\"ref)`</li></ol>`gs;  
Eric
  • 21
  • 3