RegEx

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:

([^\s][\s\S]{0,20}(?!=[^\s]))([\s]|$)

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

http://www.mrexcel.com/forum/excel-questions/76765-equivalent-instr-instrrev-excel.html

The following two tabs change content below.

allenpg

Latest posts by allenpg (see all)

Leave a Reply