Created
August 20, 2020 06:21
-
-
Save leonlaser/9feeb8ce63238b874e55cb99cc8a8112 to your computer and use it in GitHub Desktop.
[Split text after x chars] #javascript #regex
This file contains hidden or 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
// Source: https://stackoverflow.com/questions/27758483/split-text-string-at-closest-space-in-javascript | |
// Author: https://stackoverflow.com/users/1215106/%e2%84%a6mega | |
// If you are interested in just the first part, then use | |
var a = fulltext.match(/^.{47}\w*/) | |
// If you want to split the entire string to multiple substrings, then use | |
var a = fulltext.match(/.{47}\w*|.*/g); | |
// ...and if you wish substrings do not start with the word separator (such as space or comma) and prefer to include it with the previous match, then use | |
var a = fulltext.match(/.{47}\w*\W*|.*/g); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment