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

The Archive Base Latest Questions

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

I want to extract some string data from a given file. File got structure

  • 0

I want to extract some string data from a given file. File got structure such as:


name, catg, {y:2006, v:1000, c:100, vt:1}, {y:2007, v:1000, c:100, vt:1},.. {..}...


I want to extract next values:

  • name;
  • catg;
  • numbers after y, v, c, vt labels;

I used the next regexes:

  • @"(?<name>\w+), (?<cat>\w+)" for extraction of the first two items;
  • @"(?:\{y:(?<y>\d+), +v:(?<v>\d+), +c:(?<c>\d+), +vt:(?<vt>\d+)\}, ?)+" for extraction of other values enclosed in curly brackets.

I concatenated those two and made a test in regex tester. But as expected I get only one set of extracted numbers. And I need result from the other part ({y:2007, v:1000, c:100, vt:1}). Moreover there could be more than two parts.

How do I fix my regex? And then how do I collect all number sets from corresponding parts.

  • 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-22T18:23:51+00:00Added an answer on May 22, 2026 at 6:23 pm

    Here’s fixed regex (you need to specify IgnorePatternWhitespace option):

    (?'name'\w+), \s*
    (?'category'\w+), \s*
    (?:
        \{ \s*
            y: (?'y'\d+), \s*
            v: (?'v'\d+), \s*
            c: (?'c'\d+), \s*
            vt: (?'vt'\d+)
        \} \s*
        ,? \s*
    )*
    

    And here’s usage:

    String input = @"name, catg, {y:2006, v:1000, c:100, vt:1}, {y:2007, v:1000, c:100, vt:1}";
    String pattern =
          @"(?'name'\w+), \s*
            (?'category'\w+), \s*
            (?:
                \{ \s*
                    y: (?'y'\d+), \s*
                    v: (?'v'\d+), \s*
                    c: (?'c'\d+), \s*
                    vt: (?'vt'\d+)
                \} \s*
                ,? \s*
            )* ";
    RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline;
    
    Match match = Regex.Match(input, pattern, options);
    if (match.Success)
    {
        String name = match.Groups["name"].Value;
        String category = match.Groups["category"].Value;
    
        Console.WriteLine("name = {0}, category = {1}", name, category);
    
        for (Int32 i = 0; i < match.Groups["y"].Captures.Count; ++i)
        {
            Int32 y = Int32.Parse(match.Groups["y"].Captures[i].Value);
            Int32 v = Int32.Parse(match.Groups["v"].Captures[i].Value);
            Int32 c = Int32.Parse(match.Groups["c"].Captures[i].Value);
            Int32 vt = Int32.Parse(match.Groups["vt"].Captures[i].Value);
    
            Console.WriteLine("y = {0}, v = {1}, c = {2}, vt = {3}", y, v, c, vt);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use ADO.net to extract some data from an Excel file. This
I want to scrape string data from some binary text files that contain embedded
I'd like to extract the text from an HTML file using Python. I want
Using PHP Regular Expression I want to extract some value from code <?xml version=1.0
I have a string (char) and I want to extract numbers out of it.
I have barcode images in jpg format and want to extract barcode # from
Given a filename in the form someletters_12345_moreleters.ext , I want to extract the 5
I want to use Perl to extract information from a Certificate Signing Request ,
I'm trying to get data from file. The file first has three lines of
I am looking for a way to extract / scrape data from Word files

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.