maybe-baby | A JavaScript implementation | Functional Programming library
kandi X-RAY | maybe-baby Summary
kandi X-RAY | maybe-baby Summary
Minimize defensive coding. A JavaScript implementation of the Maybe monad.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of maybe-baby
maybe-baby Key Features
maybe-baby Examples and Code Snippets
Community Discussions
Trending Discussions on maybe-baby
QUESTION
I have some long but variable-length texts that are divided into sections marked by ********************
. I need to post those texts into a field that only accepts 2048 characters, so I will need to divide that text into groups of no more than 2048 characters but which do not contain an incomplete section.
My regex so far is ^([\s\S]{1,2048})([\s\S]{1,2048})([\s\S]{1,2048})
However, this has two problems:
1) It divides the text into groups that can include an incomplete section. What I want is a complete section, even if it is not a full 2048 characters. Assume the example below is at the end of 2048 characters.
Here's my actual result. Notice that the "7 Minute Workout" section is cut off mid-section
...ANSWER
Answered 2019-Aug-01 at 22:37Couple Notes:
No need to use groups at all, just use match results directly as each match represent one section.
Use lazy quantifier instead of greedy by adding
?
after{1,2048}
to make the match cut in the right place.In my regex, I used only Global
g
without the multilinem
.The code below will work only with sections that have 2048 characters or less. If the section has more than 2048 characters, it will be skipped.
The regex below uses Positive Lookahead to signal the end of the section without matching.
Here is the regex:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install maybe-baby
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page