RegEx for truncating & trimming

I’m always a bit excited after writing a fairly succinct-yet-powerful regular expression, so I thought I’d take a short break from the WebGL topics for this tidbit:


This magical regex will trim & truncate text down to 20 characters without breaking apart the last word. Need a different number of characters? Just change the “20″ to whatever you need.


A link to some search/replace inside excel: – in terms of truncating string after the URL

The following two tabs change content below.


Latest posts by allenpg (see all)

Leave a Reply