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 6669539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:09:43+00:00 2026-05-26T03:09:43+00:00

I am relatively new with Regular Expressions so please excuse me. I am currently

  • 0

I am relatively new with Regular Expressions so please excuse me.

I am currently trying to group each line based on the record line. So, for example, I want all lines proceding the record Line to be grouped into one string, until the next record line. I have been trying to use regular expressions, and I have obtained a result that is very close to what I want, however, there is a newline present at the beginning of the array that I am reading it into.

This is the code I am using to split the data up.

        using (StreamReader sr = new StreamReader(file))
        {
            string line;
            line = sr.ReadToEnd();
            string[] parts = Regex.Split(line, @"(?=PA11)");

            List<string> parameterList = new List<string>(parts);

            foreach (string s in parameterList)
            {
                listBox1.Items.Add(s);
            }
        }

And this is the result looks like this:

*newline*
LINE 000001 000001 TEST A B TEST OUTPUT *More Lines*                
LINE 000002 000002 TEST A B TEST OUTPUT *More Lines*                  

If anyone can tell me what it is I am doing wrong, I would greatly appreciate it. Thank you in advance.

  • 1 1 Answer
  • 0 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-26T03:09:43+00:00Added an answer on May 26, 2026 at 3:09 am

    Looks to me like it’s not inserting a newline but a blank entry. Your regex matches the very beginning of the input because the first line starts with PA11, and it doesn’t consume any characters, so the first item in the parts array is an empty string. You should be able to prevent that by forcing the regex to consume some characters, such as the newline preceding the PA11 line:

    string[] parts = Regex.Split(line, @"[\r\n]+(?=PA11)");
    

    …or by making sure it doesn’t match unless there’s a newline before PA11:

    string[] parts = Regex.Split(line, @"(?<=[\r\n])(?=PA11)");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still relatively new to Regular Expressions and feel My code is being
I'm relativly new to regular expressions but I managed to create a working expression
Relatively new to dealing with XML in jQuery. I am trying to retrieve a
I am relatively new to Silverlight development and I am trying to figure out
Relatively new to rails and trying to model a very simple family tree with
Im relatively new to iPhone development and Im trying to implement Facebook functions in
I am relatively new to Grails, and want to learn more about how to
I'm relatively new to C. In Kochan's Programming in C I'm currently on if-else
Am relatively new to C# and coding in general. I am trying to write
Relatively new to MVC and trying to get a cascading dropdown list working for

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.