Need regex for multiple carriage returns

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Extremest
Forum Commoner
Posts: 84
Joined: Mon Aug 29, 2005 12:39 pm

Need regex for multiple carriage returns

Post 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?
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Need regex for multiple carriage returns

Post by prometheuzz »

Split on the occurrence of two of the following (succeeding) patterns:

Code: Select all

'/\r\n|[\r\n]/'
Extremest
Forum Commoner
Posts: 84
Joined: Mon Aug 29, 2005 12:39 pm

Re: Need regex for multiple carriage returns

Post by Extremest »

I am not very good to regex. What do you mean split on occurence of 2 of those.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Need regex for multiple carriage returns

Post 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")
Extremest
Forum Commoner
Posts: 84
Joined: Mon Aug 29, 2005 12:39 pm

Re: Need regex for multiple carriage returns

Post 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.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Need regex for multiple carriage returns

Post 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?
Post Reply