Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3274790
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:04:35+00:00 2026-05-17T19:04:35+00:00

I have a text file that contains more or less paragraphs. The text is

  • 0

I have a text file that contains more or less paragraphs. The text is not actually words, its comma delimited data; but that’s not really that important. The text file is sort of divided into sections; there can be sections, and subsections. The division of sections is denoted by more than one newlines and subsections by a newline.

So sample data:

This is the, start of a, section
908690,246246246,246246
246246,246,246246

This is, the next, section,
sfhklj,sfhjk,4626246
4yw2,fdhds5juj,53ujj

So the above data contains two sections, each with three subsections. Sometimes however, there is more than one empty line between sections. When this occurs, I want to convert the multiple newline characters, say \n\n\n\n to just \n\n; I think regex is probably the way to do this. I also may need to use different newline standards, unix \n, and windows \r\n. I think the files probably contain multiple endline encodings.

Here is the regex that I’ve come up with; its nothing special:

Regex.Replace(input, @"([\r\n|\n]{2,})", Enviroment.NewLine + Enviroment.NewLine}

Firstly, is this a good regex solution? I’m not that good with regex.

Secondly, I then want to split each section into an element in a string array:

Regex.Split(input, Enviroment.NewLine + Enviroment.NewLine)

Is there a way to combine these steps?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:04:35+00:00Added an answer on May 17, 2026 at 7:04 pm

    [\r\n|\n] is wrong. That’s a character class that matches one of the characters \r, \n, or |.

    Common idioms for matching a generic line separator are (?:\r\n|[\r\n]) or (?:\n|\r\n?). These will match \r\n (DOS/Windows), \r (older Macintosh), or \n (Unix/Linux/Mac OS X).

    I would normalize all line separators to \n, then split on two or more of those:

    Regex.Split(Regex.Replace(source, @"(?:\r\n|[\r\n])", "\n"), @"\n{2,}")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Text file that contains data separated with a comma , . How
I have a text file that contains a list of filenames, minus the extension,
I have a text file that contains unix style line endings: a 0x0A at
Am using vim and have a large text file that contains some html thrown
I have this text file that contains approximately 22 000 lines, with each line
I have a text file that might contain thousands and thousands of numbers(0-9 -->
I have a text file that I want to edit using Java. It has
I have a text file that looks a bit like: random text random text,
I have a text file that I want to send over the network, this
I have a text file that is pretty long. Any easy way to undo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.