Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment