Categories
Development

String will not split using Regex

As seen in the snippet, I have a Regex that should identify any empty lines. (I’m aware I can just do /n/n, but it doesn’t suit my purposes). I’ve tested it in a word editor, and it picks up every new line when using the find tool. But in JS, I’m still getting the entire file. What am I missing, here?

const mockData = `This is some fake data
with multiple sentences
  
and line breaks`;

const newArr = mockData.split(/^\s*$/);

console.log(newArr[0]);

Leave a Reply

Your email address will not be published. Required fields are marked *