I hav a string that contains a lot different HTML tags. I want to shorten it to, let's say, maximum 400 characters. The issue I have is:
I need to make shure that I don't leave open HTML tags. So let's say the text ends with
---
<a href=".....">whatever</a>
---
and the cap would be in the middle of the word "whatever", then I can't have
---
<a href=".....">whatev...
---
at the end of the string.
So I need a regular expression that does the following:
1) find end of words where I want to do the cut.
2) If an HTML tag would stay open there, then do the cut BEFORE the last HTML tag.
Can anybody help?
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.