Page 1 of 1

Need regex for multiple carriage returns

Posted: Mon Feb 23, 2009 4:43 pm
by Extremest
I have a text file that has the info seperated by 2 carriage returns. I read the whole file in with file_get_contents then I do another regex to get like the chapters seperated. Then each chapter has different sections that are seperated by 2 carriage returns. I can not figure out how to split the content with the returns can anyone help me?

Re: Need regex for multiple carriage returns

Posted: Tue Feb 24, 2009 1:22 am
by prometheuzz
Split on the occurrence of two of the following (succeeding) patterns:

Code: Select all

'/\r\n|[\r\n]/'

Re: Need regex for multiple carriage returns

Posted: Tue Feb 24, 2009 7:57 pm
by Extremest
I am not very good to regex. What do you mean split on occurence of 2 of those.

Re: Need regex for multiple carriage returns

Posted: Wed Feb 25, 2009 1:59 am
by prometheuzz
Extremest wrote:I am not very good to regex. What do you mean split on occurence of 2 of those.
Now is a good time to learn something:

http://nl2.php.net/preg_split
http://www.regular-expressions.info/repeat.html (see the paragraph "Limiting Repetition")

Re: Need regex for multiple carriage returns

Posted: Wed Feb 25, 2009 2:52 pm
by Extremest
I have tried using what he has with {2} behind it meaning it needs to have 2 of them right. It is not splitting it though. Is there a text editor out there that will show you which returns it has.

Re: Need regex for multiple carriage returns

Posted: Wed Feb 25, 2009 3:30 pm
by prometheuzz
Extremest wrote:I have tried using what he has with {2} behind it meaning it needs to have 2 of them right. It is not splitting it though. Is there a text editor out there that will show you which returns it has.
Can you provide the sample text you're testing your regex against and explain what is going wrong?