Skip to content

Instantly share code, notes, and snippets.

@kezenwa
Forked from jongacnik/smart-excerpt.js
Created July 12, 2023 14:54
Show Gist options
  • Save kezenwa/9a0c4bddb63dff4515ae2dbac222b057 to your computer and use it in GitHub Desktop.
Save kezenwa/9a0c4bddb63dff4515ae2dbac222b057 to your computer and use it in GitHub Desktop.
var striptags = require('striptags')
function smartExcerpt (string) {
var re = /(^.*?[a-zA-Z0-9\)\”\"]{2,}[.!?])[\s\”\"]+\W*[A-Z]/
var matches = striptags(string).match(re)
return matches && matches[1] ? matches[1] : string
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment