0

I have a string that looks similar to this...

[1.2.1] - 08/30/2018
### Added
1. A new POPUP

[1.2.0] - 08/16/2018
### Added
1. Created a CHANGELOG

It will always be in a similar format, there will always be an empty line in between entries. What I am attempting to do is split the string on the empty line. I am attempting to use JS's .split() method, this is what I have;

MyString.split('/([\r\n]{2})/g');

These are the results I get:

[[1.2.1] - 08/30/2018↵### Added↵1. Changes POPUP↵↵[1.2.0] - 08/16/2018↵### Added↵1. Created a CHANGELOG]

The result I expect:

[[1.2.1] - 08/30/2018↵### Added↵1. Changes POPUP],
[[1.2.0] - 08/16/2018↵### Added↵1. Created a CHANGELOG]

Not sure what I'm missing here.

-- EDIT

This is a very specific question about turning a single string into an array of text blocks, split on empty lines, not a general blanket question of "Why doesn't this regex work"

-- EDIT #2 After reviewing the comments, I have revised my method to use MyString.split(/[\r\n]{5,}/) and I had to add 2 additional empty lines between entries like so,

[1.2.1] - 08/30/2018
### Added
1. Changes POPUP



[1.2.0] - 08/16/2018
### Added
1. Created a CHANGELOG

Why must I use {5} as opposed to {4} to get the results I desire?

-- EDIT #3

After later revisiting the issue, I was able to get the desired results. In this case the solution was to use MyString.split(/[\r\n]{3,}/) and reformat the entire block of data to have two blank lines between "versions" like so;

[1.2.1] - 08/30/2018
### Added
1. Popup to alert of new updates
2. Users now have a button to show closed quotes in addition to open quotes.

### Updates
1. Table now by default, hides closed quotes.
2. Refactored color key.
3. Refactored view control buttons.


[1.2.1] - 08/30/2018
### Added
1. Changes POPUP


[1.2.0] - 08/16/2018
### Added
1. Created a CHANGELOG

Ultimately a reformat of the data structure led to the desired results.

Mark Carpenter Jr
  • 812
  • 1
  • 16
  • 32

0 Answers0