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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:45:33+00:00 2026-05-23T23:45:33+00:00

I have a file that looks like this: STUFF STUFF **X** **Y** STUFF STUFF

  • 0

I have a file that looks like this:

STUFF   STUFF       **X**     **Y**  STUFF STUFF
J6      INT-00113G  227.905    5.994  180  SOIC8    
J3      INT-00113G  227.905 -203.244  180  SOIC8     
U13     EXCLUDES    -42.210  181.294  180  QFP128    
U3      IC-00276G     5.135  198.644  90   BGA48     
U12     IC-00270G  -123.610 -201.594  0    SOP8      
J1      INT-00112G  269.665  179.894  180  SOIC16    
J2      INT-00112G  269.665  198.144  180  SOIC16    

And I need to grab the 3rd column and the 4th column seperately and store them into a list in C#.


I am currently matching the 3rd and 4th column together using:

        var xyResult = new List<string>();
        var mainResult = new List<string>();

        foreach (var mainLine in fileList)
            mainResult.Add(string.Join(" ", mainLine));

        foreach (var xyLine in mainResult)
        {
            Match xyRegex = Regex.Match(xyLine, @"[\d]+\.[\d]+\s+[\d]+\.[\d]+");

            if (xyRegex.Success)
            {
                xyResult.Add(string.Join(" ", xyRegex));
            }
        }

        List<string> finalXYResult = xyResult.ToList();

        foreach (var line in finalXYResult)
            displayXYRichTextBox.AppendText(line + "\n");

Right now I am storing the regex matching both X and Y into one list. I would like to store the two column values seperate. So, one list for X and one list for Y.


QUESTION:

  • What regex can I use to match the 3rd column of numbers and store it in “X” and also (or seperately using another regex) match the 4th column of numbers and store it in “Y”?

EDIT:

    private void calculateXAndYPlacementTwo()
    {
        // Reads the lines in the file to format.
        var fileReader = File.OpenText(filePath + "\\Calculating X,Y File.txt");

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

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

            fileList.Add(line);
        }

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

        foreach (var mainLine in fileList)
            mainResult.Add(string.Join(" ", mainLine));

        mainResult.ForEach(xyLine =>
        {
            Match xyRegex = Regex.Match(xyLine, @"(?<x>-?\d+\.\d+)\s+(?<y>-?\d+\.\d+)");
            if (xyRegex.Success)
            {
                String xValue = xyRegex.Groups["x"].Value;
                String yValue = xyRegex.Groups["y"].Value;

                xyResult.Add(String.Join(" ", new[]{ xValue, yValue }));

                foreach (var line in xValue)
                    richTextBox1.AppendText(line + "\n");

                foreach (var line in yValue)
                    richTextBox2.AppendText(line + "\n");
            }
        });
    }
  • 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-23T23:45:33+00:00Added an answer on May 23, 2026 at 11:45 pm

    To make things easier I’ve named the groups, but the following should work:

    (?<x>-?\d+\.\d+)\s+(?<y>-?\d+\.\d+)
    

    Please note that this requires both the 3rd & 4th column to have decimal numbers (I don’t do any checking to accept either whole or decimal numbers, but if necessary, this can be added).

    Note the above has been tested to work.

    Summary

    Basically we use the capture you had, but extend it using capture groups (the parenthesis). I also use named groups (the ?<x> and ?<y> at the start of the group) so you can reference the values found using xyRegex.Groups["x"] and xyRegex.Groups["y"], respectively.

    I also found your capture failed when numbers appeared with negative values, so I added an optional negative symbol (-?) to the pattern to account for that.

    So, broken down, here is the statement:

    (?<x>              # Begin capture group "x"
      -?                 # allow a negative symbol 0 or 1 time
      \d+                # allow 1+ numbers
      \.                 # allow a single decimal
      \d+                # allow decimal numbers 1+ times
    )                  # end capture group "x"
    \s+                # allow white space between the number sets
    (?<y>              # Begin capture group "y"
      -?                 # \
      \d+                #  | - same as above
      \.                 #  |
      \d+                # /
    )                  # End capture group "y"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code that looks like this: int main () { fstream file;
I have a file that looks kind of like this: junk stuff NAME Test
Let's say I have a file-system that looks a little something like this: C:\stuff\build.xml
I have a file that contain lines that looks like this: >AF001546_1 [88 -
I have a file that contain list of numbers that looks like this: 10^-92
I have a text file that looks like this: value1 value2 value3 There are
I have a very large file that looks like this (see below). I have
I have a CMakeLists.txt file that looks like this: add_executable(exec1 exec1.c source1.c source2.c source3.c)
I have an eclipse's .classpath file that looks like this: <?xml version=1.0 encoding=UTF-8?> <classpath>
--edited for clarity (hopefully) I have an XML file that looks something like this:

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.