Created
December 14, 2011 20:51
-
-
Save rhowardiv/1478461 to your computer and use it in GitHub Desktop.
contentCall function for charCount plugin to take twitter URL-shortening into account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The regex is edited down from Friedl's Mastering Regular Expressions (3rd ed. p. 76). Hope I entered it correctly; it tests okay.