troubleshooting Question

RegEx to shrink text with HTML tags

Avatar of Smoerble
SmoerbleFlag for Germany asked on
Scripting LanguagesProgramming
13 Comments1 Solution817 ViewsLast Modified:
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?
Join our community to see this answer!
Unlock 1 Answer and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros