Skip to content

Instantly share code, notes, and snippets.

@bartolsthoorn
Created October 7, 2011 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bartolsthoorn/1270335 to your computer and use it in GitHub Desktop.
Save bartolsthoorn/1270335 to your computer and use it in GitHub Desktop.
removeLastSentence = (text) ->
lastSeparator = Math.max(
text.lastIndexOf("."),
text.lastIndexOf("!"),
text.lastIndexOf("?")
)
revtext = text.split('').reverse().join('')
sep = revtext.search(/[A-Z]\s+(\")?[\.\!\?]/)
lastTag = text.length-revtext.search(/\/\</) - 2
lastPtr = if (lastTag > lastSeparator) then (lastTag) else (text.length)
if sep > -1
text1 = revtext.substring(sep+1, revtext.length).trim().split('').reverse().join('')
text2 = text.substring(lastPtr, text.length).replace(/['"]/g,'').trim()
sWithoutLastSentence = text1 + text2
else
sWithoutLastSentence = ''
return sWithoutLastSentence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment