Skip to content

Instantly share code, notes, and snippets.

@Jei
Created March 28, 2017 08:27
Show Gist options
  • Save Jei/e5746a1c31860be8068e76fd7786d1b4 to your computer and use it in GitHub Desktop.
Save Jei/e5746a1c31860be8068e76fd7786d1b4 to your computer and use it in GitHub Desktop.
Telegram message splitter regex.
// The maximum length of a Telegram text message is 4096 UTF8 characters.
// This regex splits a string in parts of 4096 characters at most, ending with newline.
exports.splitMessage = function(text) {
return text.match(/([^\s][\w\W\n]{0,4096})(?=\n[\w\W\n]*|$)/gi);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment