var wordRegEx = /([A-Za-z0-9']+)(\s)/gi;
var title = "Sandusky Admits Showering With Boys, but Says He's 'Innocent' of Sex Abuse Charges";
var title60 = title.substring(0,60);
var titleWords = title60.match(wordRegEx);
var summary="Sandusky's arrest earlier this month on charges he sexually abused at least eight boys has rocked Penn State, which fired the university president, as well as legendary football coach Joe Paterno, after criticism that they didn't go to police sooner with what they new about the allegations. ";
var summary100 = summary.substring(0, 100);
var summaryWords = summary100.match(wordRegEx);
// If the last letter was part of a word
if( summary[101].match(wordRegexp) ) {
// Throw out the last word (since it was incomplete)
summaryWords.pop();
}
var test = summaryWords.join(" ")+"...";
$(document).ready(function(){
$("#summary100").html(summary100);
$("#summaryWords").html(test);
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.