I know that a parser would best be suited for this situation but in my current situation it has to be just straight javascript.
I have a regex to find the closing body tag of an html doc.
var closing_body_tag = /(<\/body>)/i;
However, this fails when source has more than 1 body tag set. So I was thinking about going with something like this..
var last_closing_body_tag = /(<\/body>)$/gmi;
This works for the case when multiple tags are found, but for some reason it is failing on cases with just 1 set of tags.
Am I making a mistake that would cause mixed results for single tag cases?
Yes, I understand more than one body tag is incorrect, however, we have to handle all bad source.
tag is at the very end of the string, though I imagine you will usually have a
after that. It would be very helpful if you could give some example input to demonstrate what's succeeding and what's failing.
– Jon Carter Apr 24 '15 at 15:11