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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:36:47+00:00 2026-06-13T22:36:47+00:00

I have a header file which contains several struct definitions. I want to extract

  • 0

I have a header file which contains several struct definitions.
I want to extract a spesific struct from this file. For example
I need to get only second struct.

typedef struct {
  int a;
  int b;
} first;

typedef struct {
  int x;
 int y;
} second;

Below expression

...
headerText = headerFile.read()
re.match(r"typedef struct {(.*)} second;", headerText) 
...

returns

int a;
  int b;
} first;

typedef struct {
  int x;
  int y;

How can I get only the second struct?
Thanks…

  • 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-06-13T22:36:48+00:00Added an answer on June 13, 2026 at 10:36 pm

    Use this regex..just replace the second with any other required struct name

    [without groups]

    Use this regex if you dont want the groups

    typedef struct(?!.*?typedef struct).*?\}.*?\bsecond\b.*?;
    

    The above regex matches typedef struct that is not followed by another typedef struct i.e. (?!.*?typedef struct)..This is done so that multiple structs are not captured


    [with groups]

    (?:^|\;).*(typedef struct.*?\}.*?\bsecond\b.*?;)
    

    Basically the above regex matches a struct that is either at the start of the file or it would match the required struct after a statement terminator..i.e ;.This is done so that other struct definitions are not included in the result..

    (?:^|\;) matches the start of the string or a ; and doesnt get captured in the group

    .* matches 0 to many characters greedily

    (typedef struct.*?\}.*?\bsecond\b.*?;) now matches your struct

    .*? matches 0 to many characters lazily

    Group1 now has your required struct

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

Sidebar

Related Questions

i have coded a header file which contains a input textbox for search.this header
I want to reimplement a library of which I have the header file. I
I have C header file containing the following type definition: // example.h typedef struct
I have a header file. In this header I want to use a map
I have a header file which contains a member variable declaration of a static
I have a SSRS 2005 rdl file, which contains a header section. The header
I have a csv file which contains the numbers of buttons. I want to
I have A header file which contains declaration of a function, let's call it
I have a header file which contains a class with an assignment operator. Now
i have xml file which contains some details i want to pick some value

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.