# Splitting a story with double-spaced para's

**URL:** <https://www.ruby-forum.com/t/splitting-a-story-with-double-spaced-paras/97131>\
**Category:** Rails\
**Created:** [July 5, 2006, 7:00am UTC](https://www.ruby-forum.com/t/splitting-a-story-with-double-spaced-paras/97131 "2006-07-05T07:00:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 5, 2006, 7:00am UTC](https://www.ruby-forum.com/t/splitting-a-story-with-double-spaced-paras/97131/1 "2006-07-05T07:00:52Z")

</div>

Quick question - if i want to separate a long string of text, separated  
by single carriage returns, into an array of paragraphs, I can use the  
following code:

paragraphs = article.content.split("\n")

The “\n” means a carriage return, as far as I can tell.

If I wanted to take text, that had been written using the more common  
double carriage returns, into an array of paragraphs in the same  
fashion, then logically I should be able to do this:

paragraphs = article.content.split("\n\n")

Right?

However, it isn’t working. I’ve tried split("\n \n"), split("\n/\n"),  
split("\n" “\n”), all to no avail. Could somebody kindly point me in the  
right direction?

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 5, 2006, 7:18am UTC](https://www.ruby-forum.com/t/splitting-a-story-with-double-spaced-paras/97131/2 "2006-07-05T07:18:26Z")

</div>

You might be seeing a problem between the different type of new line  
characters. “\n” is a line feed, and “\r” is a carriage return. unix  
systems  
use “\n” for new lines, windows uses “\r\n”. Another possibility is that  
there is some other white space between the two new lines. If so maybe  
something like split( /\n\s\*\n/ ). Also, I would recommend using /\n/  
rather  
than “\n” to be able to match on a regex, rather than just a string.  
hope  
that helps.

mark

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 5, 2006, 7:56am UTC](https://www.ruby-forum.com/t/splitting-a-story-with-double-spaced-paras/97131/3 "2006-07-05T07:56:34Z")

</div>

Thanks Mark! Looks like you came through for me again. The /\n\s\*\n/  
worked.  
What does \s mean?

Mark Van H. wrote:

> You might be seeing a problem between the different type of new line  
> characters. “\n” is a line feed, and “\r” is a carriage return. unix  
> systems  
> use “\n” for new lines, windows uses “\r\n”. Another possibility is that  
> there is some other white space between the two new lines. If so maybe  
> something like split( /\n\s\*\n/ ). Also, I would recommend using /\n/  
> rather  
> than “\n” to be able to match on a regex, rather than just a string.  
> hope  
> that helps.
> 
> mark

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 5, 2006, 8:07am UTC](https://www.ruby-forum.com/t/splitting-a-story-with-double-spaced-paras/97131/4 "2006-07-05T08:07:50Z")

</div>

In a regex \s denotes any whitespace character ( could be a space, a  
tab, a  
newline ). The \* denotes that there could be zero, or could be any  
number of  
them in the match. Glad to help.

mark
