Skip to content

Instantly share code, notes, and snippets.

@rhowardiv
Created December 14, 2011 20:51
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 rhowardiv/1478461 to your computer and use it in GitHub Desktop.
Save rhowardiv/1478461 to your computer and use it in GitHub Desktop.
contentCall function for charCount plugin to take twitter URL-shortening into account
function contentWithTwitterURLShortening(c) {
// t.co URLs are currently max 20 chars, but since that is subject to
// expansion we're leaving some elbow room and assuming 25
return c.replace(/http(s?):\/\/[-\w]+(\.\w[-\w]*)+(:\d+)?(\/[^.!,?;"'<>()\[\]{}\s\x7F-\xFF]*(?:[.!,?]+[^.!,?;"'<>()\[\]{}\s\x7F-\xFF]+)*)?/g, "http$1://t.co/xxxxxxxxxxxxx");
}
@rhowardiv
Copy link
Author

The regex is edited down from Friedl's Mastering Regular Expressions (3rd ed. p. 76). Hope I entered it correctly; it tests okay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment