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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:28:22+00:00 2026-05-23T17:28:22+00:00

I have a file that I am reading in, splitting up into different lists

  • 0

I have a file that I am reading in, splitting up into different lists and outputting them into RichTextBox to then be read into 3 different Listboxes. I am currently doing all of this, however I have come across something I do not know how to fix/work around.

My code is below and I seem to be having trouble understanding why it fails to properly work when it gets to the Match twoRegex = Regex.Match(…) section of the code.

CODE:

    private void SortDataLines()
    {
        try
        {
            // Reads the lines in the file to format.
            var fileReader = File.OpenText(openGCFile.FileName);

            // Creates a list for the lines to be stored in.
            var placementUserDefinedList = new List<string>();

            // Reads the first line and does nothing with it.
            fileReader.ReadLine();

            // Adds each line in the file to the list.
            while (true)
            {
                var line = fileReader.ReadLine();
                if (line == null)
                    break;

                placementUserDefinedList.Add(line);
            }

            // Creates new lists to hold certain matches for each list.
            var oneResult = new List<string>();
            var twoResult = new List<string>();
            var mainResult = new List<string>();

            foreach (var userLine in placementUserDefinedList)
                mainResult.Add(string.Join(" ", userLine));

            foreach (var oneLine in mainResult)
            {
                // PLACEMENT ONE Regex
                Match oneRegex = Regex.Match(oneLine, @"^.+(RES|0402|0201|0603|0805|1206|1306|1608|3216|2551"
                    + @"|1913|1313|2513|5125|2525|5619|3813|1508|6431|2512|1505|2208|1005|1010|2010|0505|0705"
                    + @"|1020|1812|2225|5764|4532|1210|0816|0363|SOT)");

                if (oneRegex.Success)
                    oneResult.Add(string.Join(" ", oneLine));
            }

            //
            // THIS IS THE SECTION THAT FAILS..
            // 
            foreach(var twoLine in mainResult)
            {
                //PLACEMENT TWO Regex
                Match twoRegex = Regex.Match(twoLine, @"^.+(BGA|SOP8|QSOP|TQSOP|SOIC16|SOIC12|SOIC8|SO8|SO08"
                    + @"CQFP|LCC|LGA|OSCCC|PLCC|QFN|QFP|SOJ|SON");

                if (twoRegex.Success)
                    twoResult.Add(string.Join(" ", twoLine));
            }

            // Removes the matched values from both of the Regex used above.
            List<string> userResult = mainResult.Except(oneResult).ToList();
            userResult = userResult.Except(twoResult).ToList();


            // Prints the proper values into the assigned RichTextBoxes.
            foreach (var line in userResult)
                userDefinedRichTextBox.AppendText(line + "\n");

            foreach (var line in oneResult)
                placementOneRichTextBox.AppendText(line + "\n");

            foreach (var line in twoResult)
                placementTwoRichTextBox.AppendText(line + "\n");
        }

        // Catches an exception if the file was not opened.
        catch (Exception)
        {
            MessageBox.Show("Could not match any regex values.", "Regular Expression Match Error",
                MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
    }

QUESTIONS:

  • Does anyone understand why I am unable to to find, or fail at, the second set of REGEX?
  • With that, is there a way to fix it?
  • Suggestions please! 🙂
  • 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-23T17:28:23+00:00Added an answer on May 23, 2026 at 5:28 pm

    Haven’t you missed the pipeline character in your second regex between two lines?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that i'm reading in, then creating nested lists that i
I'm trying to read a text file that contains integers and store them into
I have a text file that is encoded in UTF-8. I'm reading it in
I have a C++ program that is reading in info from a file, that
I have a file that lists filenames, each on it's own line, and I
I have a class file that I am reading the bytes from and defining
I have a plist file that I am reading out a measurement, but some
I have a large file (bigger then RAM, can't read whole at once) and
I have a custom file type that I'm reading from and writing to within
I have a CSV file that I want to read with Ruby and create

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.