0

I would like to split a body of text such as:

var str = "This is one.  Two because of space break
This is number three! 


And Four?!?!"

Using str.match( /[^\.!\?]+[\.!\?]+/g ) from here I get the following 3.

[ 'This is one.',
  '  Two because of space break\r\n    This is number three!',
  ' \r\n\r\n\r\n    And Four?!?!' ]

Instead I would like to have 4 different and clean (no \r\n) values because of the page break. I tried using str.replace(/\r?\n/g,'.'); before the match function and that sort of works, but I was wondering if there was a cleaner way maybe by combining regexes?

I would like to get:

['This is one.', 'Two because of space break', 'This is number three!', 'And Four?!?!']
Community
  • 1
  • 1
Squirrl
  • 4,909
  • 9
  • 47
  • 85

1 Answers1

2

Is this what you want?

str.match(/[^\s.!?]+[^.!?\r\n]+[.!?]*/g);
jcaron
  • 17,302
  • 6
  • 32
  • 46